我想将根位置(/)传递给端口3000,将/ api位置传递给端口5000,完全有可能,对吧?
我的nginx配置文件:
server {
listen 80;
server_name mywebsite.com;
location /api {
proxy_pass http://localhost:5000;
}
location / {
proxy_pass http://localhost:3000;
}
}
如果我在本地执行api请求,我可以获得预期的输出:
myuser@myserver [conf.d]# curl localhost:5000
Hello, World!myuser@myserver [conf.d]#
但没有api客户端,并且从根路径到端口3000的proxy_pass在浏览器和api客户端中正常工作
注意:
sudo systemctl reload nginx
重新加载nginx ufw
来允许两个端口的流量centos 7
答案 0 :(得分:0)
我认为您正在使用React和nodejs。我使用下面的配置。
server {
listen 80;
server_name mywebsite.com;
location / {
# My react
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /api{
# This is my nodejs API
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}