zoukankan      html  css  js  c++  java
  • [转]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是一个好习惯

  • 相关阅读:
    Centos网络时好时超时问题解决
    关于C#异常的处理
    获取Excel工作薄中Sheet页(工作表)名集合
    C# shell32.dll 的用法
    C#将Excel数据表导入SQL数据库的两种方法
    Modbus RTU通信协议详解以及与Modbus TCP通信协议之间的区别和联系
    C# 多线程、异步、同步之间的联系与区别
    在C#中使用Panel控件实现在一个窗体中嵌套另一个窗体
    HslCommunication组件库使用说明
    C#判断dataGridView1 点击的是哪一列上的按钮
  • 原文地址:https://www.cnblogs.com/liugx/p/7719953.html
Copyright © 2011-2022 走看看