HstarDoc icon indicating copy to clipboard operation
HstarDoc copied to clipboard

Nginx托管单页配置

Open hstarorg opened this issue 8 years ago • 3 comments

location / {
  root /dist;
  try_files $uri $uri/ /index.html; # process history
  error_page 404 /index.html; #process history
}

hstarorg avatar Jul 12 '17 09:07 hstarorg

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 avatar Sep 10 '17 16:09 MrTreasure

@MrTreasure 这是反向代理了。你可以在2001端口对应的配置上处理这个问题。

hstarorg avatar Sep 11 '17 01:09 hstarorg

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;
        }

MrTreasure avatar Sep 11 '17 04:09 MrTreasure