码迷,mamicode.com
首页 > 其他好文 > 详细

nginx虚拟目录(alias与root的区别)

时间:2015-07-03 20:37:40      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

原文地址:http://blog.sina.com.cn/s/blog_6c2e6f1f0100l92h.html

nginx虚拟目录(alias与root的区别)

今天配置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是一个好习惯

nginx虚拟目录(alias与root的区别)

标签:

原文地址:http://www.cnblogs.com/tongpao/p/4619585.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!