请教一个 nginx 的规则写法

2016-10-09 14:42:42 +08:00
 mhtt

一个 nodejs 的程序, node app.js 后的访问地址是 http://127.0.0.1:6000,下面是我的 nginx 的配置

server {
listen 80;
        server_name domain.com;
        location / {
                proxy_pass https://127.0.0.1:6000;
        }
}

可以通过 domain.com 直接访问该程序,正常,但我现在想通过 domain.com/blog 这样的方式访问这个 nodejs 程序,而 domain.com 则访问指定的地址, nginx 改成如下

server {
listen 80;
        server_name domain.com;
        root /sites;
        index index.html index.htm;
}

那么 domain.com/blog 该如何配置呢?

是不对的,请教正确的方式是?

918 次点击
所在节点    问与答
4 条回复
jackysc
2016-10-09 14:46:18 +08:00
server {
listen 80;
server_name domain.com;
root /sites;
index index.html index.htm;
location /blog {
proxy_pass https://127.0.0.1:6000;
}
}
ryd994
2016-10-09 15:18:27 +08:00
@jackysc 不,要 proxy_pass https://127.0.0.1:6000/; 最后的斜杠会替换 /blog/路径
而且要正常工作的话,可能还需要 http_sub 替换引用的链接
yangg
2016-10-09 15:41:13 +08:00
try_files

server {
listen 443 ssl http2;
server_name www.uedsky.com;
include ssl.conf;

location / {
root /var/www/uedsky.www/current/public;
try_files $uri $uri/index.html @site;
# expires 30d;
}
location @site {
proxy_pass http://127.0.0.1:3333;
proxy_set_header Host $http_host;
}
}
yangg
2016-10-09 15:42:05 +08:00
没看清要求,忽略。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/311380

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX