代码之家  ›  专栏  ›  技术社区  ›  Bidyut

nginx重定向到nginx的根目录

  •  1
  • Bidyut  · 技术社区  · 8 年前

    我在跑步 nginx 正在监听9000号端口。

    重定向规则如下:

    1. 任何东西 / 应该去 index.html 是的。
    2. 任何东西 /rest 应将请求转发到后台服务。
    3. 除了 rule 1 rule 2 应该转发到 规则1 或index.html

    我的样品 Nginx公司 配置文件如下:

     server {
     listen       9000;
     server_name  localhost;
    
     location / {
         root   /usr/share/nginx/html;
         index  index.html index.htm;
     }
    
     error_page 404 403 405 500 502 503 504 = @notfound;
    
     location /rest {
          proxy_pass http://localhost:12000;
     }
    
     location @notfound {
         return 301 http://localhost/;
     }
    }
    

    我的重定向无法正常工作,它将重定向到 http://localhost 而不是 http://localhost:9000 是的。

    谁能指出我错在哪里吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Tarun Lalwani    8 年前

    return 301 http://localhost/; 应该是 return 301 http://localhost:9000/;