Nginx 重定向到 nginx 的 root
Nginx Redirect to root for nginx
我是 运行 nginx
,正在侦听端口号 9000。
重定向规则如下:
/
的任何内容都应该转到 index.html
。
/rest
的任何内容都应将请求转发到后台服务。
- 除
rule 1
和 rule 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/;
我是 运行 nginx
,正在侦听端口号 9000。
重定向规则如下:
/
的任何内容都应该转到index.html
。/rest
的任何内容都应将请求转发到后台服务。- 除
rule 1
和rule 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/;