今天配置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. python使用安装ipdb

    1.安装 python3版本直接执行pip install ipdb命令安装 python2.7版本的需要指定ipdb的版本 pip install ipdb==0.10.2 等号后面的就是版本,因为 ...

  2. 最近玩了一下qt5.2.1,顺着写点东西,关于这个版本设置程序主窗口居中

    #include <QtGui/QGuiApplication> #include <QDebug> #include <QScreen> #include &qu ...

  3. iOS-如何写好一个UITableView

    如何写好一个UITableView 字数5787 阅读3745 评论25 喜欢69 本文是直播分享的简单文字整理,直播共分为上.下两部分.第一部分:优酷 Or YouTube,第二部分:优酷 Demo ...

  4. Java进阶7并发优化4——JDK并发数据结构

    Java进阶7并发优化4——JDK并发数据结构20131114 由于并发程序和串行程序的不同特点,在串行程序中使用的数据结构可能无法在并行程序中直接的正常使用,因为这些数据结构可能不是线程安全的,所以 ...

  5. VPS安装metasploit-framework

    一.安装过程 在/etc/apt/sources.list添加kali源: root@localhost:~# cat >> /etc/apt/sources.list <<  ...

  6. 报错:Type mismatch: cannot convert from Object to Car

    问题描述: 一个非常简单的spring项目,用静态工厂方法配置bean实例.项目的目录结构如下: 代码如下: Car.java package com.tt.spring.beans.factory; ...

  7. weblogic、hibernate 包冲突

    解决办法: 在weblogic 配置  [paths]项中 添加antlr-2.7.7.jar,该jar包应该位于引用weblogic.jar之前,使启动时不再加载weblogic中的低版本的antl ...

  8. SpringMVC札集(10)——SSM框架整合

    自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...

  9. pdf 转图片,提取图片研究心得

    1.pdf 中的数据是有多种编码的,详情请看:http://www.cnblogs.com/zendu/p/7644465.html 2.我的工作场景比较特殊,pdf中全部是图片,所以pdf转图片就有 ...

  10. 使用PullToRefreshListView时遇到Item点击事件失效问题 解决方法

    最近在自己的项目中使用到了以下开源项目: https://github.com/nanchen2251/pullToRefreshDemo 相关介绍博客如下: http://www.cnblogs.c ...