Nginx子目录根问题

时间:2015-05-18 16:34:12

标签: wordpress nginx

我在/usr/local/nginx/html有一个webroot。 (本地主机)

我在/usr/local/nginx/html/hi.com/public安装了WordPress。

我想从http://localhost/hi.com访问WordPress安装。

这是我的配置搞砸了:

  location /hi.com {
      root /usr/local/nginx/html/hi.com/public;
  }

当我转到http://localhost/hi.com/humans.txt时,它会尝试从humans.txt抓取/usr/local/nginx/html/hi.com/public/hi.com/humans.txt,而不是从所需的/usr/local/nginx/html/hi.com/public/humans.txt位置抓取。{/ p>

关于我如何解决这个问题的任何想法?

已经杀了我。

1 个答案:

答案 0 :(得分:1)

此处的问题是您使用的是root而不是alias

  • root将以这种方式运作(Nginx guide):

    location /hi.com/ {
        root /usr/local/nginx/html/hi.com/public/;
    }
    
    • 获取:http://localhost/hi.com/humans.txt
    • 回应:/usr/local/nginx/html/hi.com/public/hi.com/humans.txt
  • alias将以这种方式运作(Nginx guide):

    location /hi.com/ {
        alias /usr/local/nginx/html/hi.com/public/;
    }
    
    • 获取:http://localhost/hi.com/humans.txt
    • 回应:/usr/local/nginx/html/hi.com/public/humans.txt

为此目的,正确的选择是使用alias

相关问题