请教 nginx 的配置

2017-06-10 23:10:37 +08:00
 Jacky001

我想设置一个网站,域名 abc.com 访问是指向 /var/www/html/abc.com/ 这里面的程序,访问 abc.com/other 访问的是 /var/www/html/other/ 这里的网页内容,

server {
        listen 80;
        server_name abc.com;
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://127.0.0.1:1234;
                proxy_redirect off;
        }
        location /other/ {
                root /var/www/html/other/;
                index index.htm index.html;
        }
}

我用上面的配置,abc.com 能正常访问,但 abc.com/other 的访问显示 404,root 换成 alias 也不行,请问正确的配置是?

1312 次点击
所在节点    问与答
7 条回复
sundong
2017-06-10 23:24:22 +08:00
/var/www/html/other/ 下面放 html 没?
若没有 随意放一个 放一个 然后 curl -I 看下
Jacky001
2017-06-10 23:25:08 +08:00
@sundong 放了 index.htm
boro
2017-06-10 23:38:04 +08:00
访问的是二级目录,配置文件 Server Name 确指向是 abc.com,不行的。除非你把 other 放到 /abc 里面,但这样就不需另外配置一个站点文件。
Jacky001
2017-06-10 23:40:34 +08:00
@sundong
@boro 我写错了,正确写法应该是

```
location /other/ {
root /var/www/html;
index index.htm index.html;
}
```
sundong
2017-06-10 23:51:58 +08:00
@Jacky001 我们不够细心哈 =。=
just1
2017-06-11 01:29:45 +08:00
不应该用 root 要用 alias
julyclyde
2017-06-11 23:18:13 +08:00
说白了,nginx 没限定“ root 只能在 server 里”就是个很大的问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/367531

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX