linux配置nginx虚拟目录
今天配置awstats,awstats创建出的文件目录在/home/awstats下,在nginx中加入配置后狂报404,发现还是忽略了root和alias的区别,特将修改配置记录如下:
1.失败:server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
root /home/awstats/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
2.失败: server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
alias /home/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
3.成功: server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
alias /home/awstats/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
4.成功: server {
server_name test.com;
charset utf-8,GB2312;
index index.html;
location / {
root html;
access_log logs/access.log main;
}
location ~ ^/awstats/ {
root /home/;
index index.html;
access_log off;
error_log off;
charset gb2312;
}
从以上例子很明显看出,还是对root和alias的概念搞混了~
1. location ~ ^/awstats/ {
root /home/awstats/;
访问:http://test.com/awstats/ 实际访问的是/home/awstats/awstats/
2. location ~ ^/awstats/ {
alias /home/
访问:http://test.com/awstats/ 实际访问的是/home/
3. location ~ ^/awstats/ { #使用alias时目录名后面一定要加“/”
alias /home/awstats/;
访问:http://test.com/awstats/ 实际访问的是/home/awstats/
4. location ~ ^/awstats/ {
root /home/;
访问:http://test.com/awstats/ 实际访问的是/home/awstats/
借用ayou老师的一句话:
一般情况下,在location /中配置root,在location /other中配置alias是一个好习惯
====================================================================
我的需求是这样的,系统有一个专门的文件夹用于存放图片,css,js或者附件,如:
http://www.test.com/resources/images/a.jpg
http://www.test.com/resources/css/a.css
http://www.test.com/resources/js/a.js
http://www.test.com/resources/attach/a.doc
这样的配置对于apache来说那相当容易,
需要通过location uri规则匹配访问到该文件夹,我使用如下配置:
location ^~ /resources/ {
root d:/www/;
}
试了N多次都能访问不到,一直报404,无比杯具!最后拜读了上面提供的blog才解决,发现跟原博主一样,没有真正搞清楚,location中root和alias的区别,最后修改成:
location ^~ /resources/ {
alias d:/www/;
}
成功实现了我的需求。
原贴如下:
niginx 似乎没有虚拟目录的说法,但是可以指定请求路径时nginx访问的路径,也算是一个解决办法。
server {
listen 80 default;
server_name _;
location / {
root html;
index 403.html;
}
location ~ //.ht {
deny all;
}
location /phpadmin/ {
alias /opt/www/phpadmin/;
index index.php;
}
location ~ /.php$ {
include httpd.conf;
}
}
要注意的是, location /phpadmin/ {} 和 location /phpadmin {} 是完全不同的。
前者可以访问到目录,而后者将被重定向到服务器,如: http://127.0.0.1/phpadmin ,将被重定向到 http://_/phpadmin
下面这个配置和上面基本类似,唯一的不同是,所有对 /phpadmin/的访问将正确解析,而其他访问则返回页面不存在(404)的信息。
server {
listen 80 default;
server_name _;
location / {
root html;
#index 403.html;
return 404;
}
location ~ //.ht {
deny all;
}
location /phpadmin/ {
alias /opt/www/phpadmin/;
index index.php;
}
location ~ /.php$ {
include httpd.conf;
}
}
linux配置nginx虚拟目录相关推荐
- Ubuntu Linux配置Nginx+MySQL+PHP+phpMyAdmin详细步骤
博主之前一直用的是apache,随着网站负荷量增高,感觉apache稍微有点力不从心了.随着nginx越来越流行,而且其功能强大,博主准备采用nginx作为自己的服务器啦. 每当到了环境配置的时候,博 ...
- Nginx虚拟目录alias和root目录
nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的: 1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在ali ...
- nginx虚拟目录支持PHP,nginx“虚拟目录”不支持php的解决方法
nginx"虚拟目录"不支持php的解决办法 这几天在配置Nginx,PHP用FastCGI,想装一个phpMyAdmin管理数据库,phpMyAdmin不想放在网站根目录 下,这 ...
- Nginx虚拟目录设置
location ~ .*\.html$ 匹配所有以.html结尾的链接 --------------------------------------------------------- 关于a ...
- TOMCAT6.0配置(虚拟目录的设置+多域名绑定)
TOMCAT6.0配置(虚拟目录的设置+多域名绑定) Tomcat6.0配置(虚拟目录的设置+多域名绑定) Tomcat6.0配置(虚拟目录的设置+多域名绑定) 优点:tomcat6.0可以自动更新类 ...
- 配置tomcat虚拟目录后无法启动tomcat
配置tomcat虚拟目录后无法启动tomcat,报错Failed to start component [StandardServer[8005]] 问题只是因为这个虚拟目录对应的真实路径不存在
- nginx虚拟目录配置
2019独角兽企业重金招聘Python工程师标准>>> 今天搞了N久的虚拟目录配置,在几乎要放弃的时侯偶然看到一篇文章,将我的问题搞定 原贴地址:http://blog.sina.c ...
- linux下创建nginx虚拟目录详解,通过Samba映射Linux磁盘作为Windows IIS的虚拟目录--梦飞翔的地方(梦翔天空)...
对于Windows和Linux共存的网站,头疼的问题之一是数据共享.例如,网站有大量静态网页,这些页面由WINDOWS动态站点生成,由LINUX的NGINX(或APACHE.LIGHTHTTP)展示, ...
- nginx虚拟目录设置 alias 和 root
nginx貌似没有虚拟目录的说法,因为它本来就是完完全全根据目录来设计并工作的. 如果非要给nginx安上一个虚拟目录的说法,那就只有alias标签比较"像",干脆来说说alias ...
最新文章
- [architecture]-armv8-aarch64种的SIMD/FP指令介绍
- VTK:Points之DensifyPoints
- Linux 汇编学习
- 用javascript写Android和iOS naitve应用,实在炫酷。
- 如何检查python的库是否安装成功_Python——查看安装位置和安装的库
- PSIM软件BUCK转换数字控制官方例程
- 使用extundelete恢复测试liunx的删除文件
- 自定义 Dialog --- 仿照微信删除联系人界面
- php 页面跳转 url地址不变,【后端开发】php跳转页面url不变
- imageJ下载 安装插件
- 【ESP 保姆级教程】疯狂点灯篇 —— 案例:ESP8266 + LED + 按键 + 阿里云生活物联网平台 + 公有版App + 天猫精灵(项目:我之家)
- 王阳明心学的最高境界
- 阄阄乐-IOS抓阄抽签工具
- 手机浏览器类型ua php,通过userAgent判断手机浏览器类型
- HDU 5869 Different GCD Subarray Query (数学gcd+树状数组离线查询)
- mysql写系统_一个用PHP和MYSQL写的定饭系统_PHP
- 晶圆封装bonding
- 大数据 就业 缺口_大数据就业前景广阔,大数据人才紧缺,岗位缺口大
- 老子云打造3D技术云服务平台,加速三维互联网变革进程
- wpf展开树节点_WPF中展开一个TreeView控件的所有树节点
热门文章
- mstsc连接远程桌面如何挂载本地磁盘
- 【VMware vSAN 6.6】5.1.基于存储策略的管理:vSAN硬件服务器解决方案
- 苹果开源Swift底层非阻塞I/O框架SwiftNIO
- 我是架构师--设计模式-单例模式
- word标题文字居中浅谈
- 201671010128 2017-09-17《Java程序设计》之步步深入面向对象
- 行业洞察驱动安全防御严峻安全挑战迎刃而解
- JBoss Seam 3.0.0.Beta1 发布
- [推荐]在线测试你的网速
- [WPF疑难] 模式窗口被隐藏后重新显示时变成了非模式窗口