今天配置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. Ansible 小手册系列 十九(常见指令表)

    Play 指令 说明 accelerate 开启加速模式 accelerate_ipv6 是否开启ipv6 accelerate_port 加速模式的端口 always_run   any_error ...

  2. java中容器的学习与理解

    以前一直对于java中容器的概念不理解,虽然学习过,但始终没有认真理解过,这几天老师提出了这样一个问题,你怎么理解java中的容器.瞬间就蒙了.于是各种搜资料学习了一下,下面是我学习后整理出来的的一些 ...

  3. js 返回上一页和刷新以及页面跳转

    1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forw ...

  4. Yii2学习笔记:汉化yii,设置表单的描述(属性标签attributeLabels)

    一:汉化框架 框架汉化在这里设置,如果不生效,前台后台的配置文件都设置下应该就可以了 二:汉化表单 汉化表单,直接在模型层设置,例如: 原来的联系我们表单 汉化后: ] 这种汉化在哪里修改呢?其实是设 ...

  5. Django中间件(勾子函数)使用

    中间件 Django中的中间件是一个轻量级.底层的插件系统,可以介入Django的请求和响应处理过程,修改Django的输入或输出.中间件的设计为开发者提供了一种无侵入式的开发方式,增强了Django ...

  6. 设计 react 组件

    重新设计 React 组件库 诚身 7 个月前   在 react + redux 已经成为大部分前端项目底层架构的今天, 让我们再次回到软件工程界一个永恒问题的探讨上来, 那就是如何提升一个开发团队 ...

  7. Spring AOP的使用报错!

    用构造方法注入的时候 需要把无参构造方法手动加上 AOP底层会调用无参构造方法. 不加则报错:Superclass has no null constructors but no arguments ...

  8. Java基础拾遗(一)

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76358391冷血之心的博客) 马上就要秋招了,新的一轮笔试面试马上 ...

  9. 理解Scala中的Extractor

    引言 最近抱着<Programming in Scala>(英文第二版)在死啃Scala.在阅读第26章Extractor时,偶然在Stack Overflow上搜到一个帖子<Sca ...

  10. Python 中的 if __name__ == '__main__'

    __name__ 是当前模块名,当模块被直接运行时模块名为 __main__ .这句话的意思就是,当模块被直接运行时,以下代码块将被运行,当模块是被导入时,代码块不被运行. 先来个小栗子: 先创建一个 ...