今天配置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 小手册系列 十六(Playbook Debug)

    debug模块在执行期间打印语句,并且可用于调试变量或表达式,而不必停止playbook. 打印自定义的信息 - debug: msg="System {{ inventory_hostna ...

  2. vue请求本地json数据

    1.下载vue-resource插件 cnpm install vue-resource 1.2全局引入vue-resource: 在main.js import VueResource from ' ...

  3. 1: 介绍Prism5.0 Introduction to the Prism Library 5.0 for WPF(英汉对照版)

     Prism provides guidance designed to help you more easily design and build rich, flexible, and easy- ...

  4. CF445

    题解: xjb乱判断一下就可以了 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; int n, ...

  5. LeetCode OJ:Add and Search Word - Data structure design(增加以及搜索单词)

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  6. IIS站点/虚拟目录中访问共享目录(UNC)以及建立后的应用程序的信任级别问题

      UNC是 Universal Naming Convention 的简称,也叫通用命名规范.通用命名约定.网络(范指局域网)上资源的完整位置名称.格式为 \\servername\sharenam ...

  7. FusionCharts制作实时刷新图

    转自:http://yklovejava-163-com.iteye.com/blog/1889949 下面介绍的是用FusionCharts制作实时刷新图的过程(FusionCharts确实太好用了 ...

  8. linux配置PHP环境!!(云服务器架设)

    首先去阿里云或腾讯云购买主机(腾讯云现在有免费30天的云主机...) 购买好之后选择安装: 点登陆 就可以到linux的操作界面了 进入操作界面 输入root账号密码取得权限之后就可以开始配置环境了 ...

  9. mybatis环境搭建和开发步骤

    环境搭建 第一步:导入jar包 第二步:导入核心配置文件(mybatis-config.xml) <?xml version="1.0" encoding="UTF ...

  10. EasyPlayer RTSP Windows(with ActiveX/OCX插件)播放器支持H.265播放与抓图功能

    EasyPlayer作为业界一款比较优秀的RTSP播放器,一直深受用户的好评,经过了近3年的开发和迭代,从一开始的简单PC版本的RTSP播放功能,到如今支持PC(支持ocx插件).Android.iO ...