Nginx 重定向到 nginx 的 root

Nginx Redirect to root for nginx

我是 运行 nginx,正在侦听端口号 9000。

重定向规则如下:

  1. / 的任何内容都应该转到 index.html
  2. /rest 的任何内容都应将请求转发到后台服务。
  3. rule 1rule 2 之外的任何内容都应转发至 rule 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

谁能指出我哪里做错了。

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