HstarDoc
HstarDoc copied to clipboard
Nginx托管单页配置
location / {
root /dist;
try_files $uri $uri/ /index.html; # process history
error_page 404 /index.html; #process history
}
location / {
#root html;
#index index.html index.htm;
proxy_pass http://localhost:2001;
#try_files $uri $uri/ /index.html;
error_page 404 /index.html;
}
这样会有问题,我的API也是这个域名下,导致全部被拦截请求不到了。
@MrTreasure 这是反向代理了。你可以在2001端口对应的配置上处理这个问题。
location /api {
proxy_pass http://localhost:2001;
}
为对应 api 接口做另外的配置,在 nginx 中如果请求是xxx/api,那么 nginx中的 /api 会优先响应,这一点和 exprss 不同。 另外这里反向代理的服务器并不是页面文件并不是 html 而是 jsp,ftl 这些需要处理的文件,那么nginx 只转发请求就好了
location / {
proxy_pass http://localhost:2001;
try_files $uri $uri/ /;
error_page 404 /index.html;
}