V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Jacky001
V2EX  ›  问与答

请教 nginx 的配置

  •  
  •   Jacky001 · 2017-06-10 23:10:37 +08:00 · 1308 次点击
    这是一个创建于 2529 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想设置一个网站,域名 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 也不行,请问正确的配置是?

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

    ```
    location /other/ {
    root /var/www/html;
    index index.htm index.html;
    }
    ```
    sundong
        5
    sundong  
       2017-06-10 23:51:58 +08:00
    @Jacky001 我们不够细心哈 =。=
    just1
        6
    just1  
       2017-06-11 01:29:45 +08:00 via Android
    不应该用 root 要用 alias
    julyclyde
        7
    julyclyde  
       2017-06-11 23:18:13 +08:00
    说白了,nginx 没限定“ root 只能在 server 里”就是个很大的问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2522 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:08 · PVG 00:08 · LAX 09:08 · JFK 12:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.