今天配置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的区别)的更多相关文章

  1. Nginx虚拟目录alias和root目录

    nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的:1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alia ...

  2. Nginx设置alias实现虚拟目录 alias与root的用法区别

    Nginx 貌似没有虚拟目录的说法,因为它本来就是完完全全根据目录来设计并工作的.如果非要给nginx安上一个虚拟目录的说法,那就只有alias标签比较"像",干脆来说说alias ...

  3. Nginx虚拟目录(alias)和根目录(root)

    功能要求: 假设nginx配置的域名是www.kazihuo.com,现有静态资源/home/www/oye目录需要通过nginx访问. 功能实现: 前提要求: 1.在nginx.conf中到处第二行 ...

  4. Nginx虚拟目录设置

    location ~ .*\.html$   匹配所有以.html结尾的链接 --------------------------------------------------------- 关于a ...

  5. Nginx 虚拟目录和虚拟主机的配置

    nginx.conf 配置文件的几个常用命令 nginx 配置文件主要分为六个区域: main: 全局设置 events: nginx工作模式 http: http设置 sever: 主机设置 loc ...

  6. nginx虚拟目录实现两个后台使用

    购买了阿里云机器,准备搭建一套备份的后台,由于资源有限所以将两个后台搭建到一组SLB下的两台WEB上. 使用软件:NGINX+PHP root@xx conf.d]# yum install php- ...

  7. Nginx(alias 和 root的区别)

    Nginx(alias 和 root的区别)1.alias 和 root 的区别: location /request_path/image { root /local_path/image/; } ...

  8. nginx“虚拟目录”不支持php的解决办法

    这几天在配置Nginx,PHP用FastCGI,想装一个phpMyAdmin管理数据库,phpMyAdmin不想放在网站根目录 下,这样不容易和网站应用混在一起,这样phpMyAdmin的目录就放在别 ...

  9. nginx的alias与root的区别

    root的写法: location /request_path/image/ { root /local_path/image/; } 这样配置的结果就是当客户端请求 /request_path/im ...

随机推荐

  1. rabbitmq&&erlang 安装

    # yum install epel-release CentOS and Red Hat Enterprise Linux 6.x wget https://dl.fedoraproject.org ...

  2. 详解offset

    offset offset 译为“偏移量”,是javascript很重要的一个概念.涉及到便宜量的主要有offsetLeft.offsetTop.offHeight.offsetWidth这四个属性还 ...

  3. 连接GitHub的方法

    连接到GitHub 首先在本地创建 ssh key: ssh-keygen -t rsa -C "your_email@youremail.com" 后面的 your_email@ ...

  4. bzoj2501

    题解: 显然,每当进入一个小的边界,那么我们的ans+1,出去一个大的边界,ans-1 然后,我们将每一个边界排序,时间小的在前,大的在后 每一次进来一个,如果是左边的边界,+1,右边的-1 然后输出 ...

  5. HDU 4549 M斐波那契数列(矩阵快速幂+费马小定理)

    M斐波那契数列 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submi ...

  6. core文件介绍

    原文链接:http://team.eyou.com/?p=27 如有侵犯您的版权,请联系windeal12@qq.com linux下,产生core文件,和不产生core文件的条件: 当我们的程序崩溃 ...

  7. TCP 初步认识

    TCP连接的建立---三次握手 第一次握手:客户端TCP首先给服务器端TCP发送一个特殊的TCP数据段. 该数据段不包含应用层数据,并将头部中的SYN位设置为1,所以该数据段被称为SYN数据段. 另外 ...

  8. python3精简笔记(二)——函数

    函数 下面的地址可以查看函数: https://docs.python.org/3/library/functions.html 也可以在交互式命令行通过help()查看函数的帮助信息. 如: > ...

  9. IOS开发 CocoaPods 使用 pod Install 出现 Updating local specs repositories

    pod install 换成pod install --verbose --no-repo-update这个命令,前面的命令被墙了

  10. OpenFlow技术白皮书-V1.0

    1.  概述 OpenFlow是由斯坦福大学的Nick McKeown教授在2008年4月ACM Communications Review上发表的一篇论文OpenFlow: enabling inn ...