【发布时间】:2020-06-02 21:09:53
【问题描述】:
所以我的堆栈在 Digital Ocean 液滴上运行。初始 node.js 应用程序在 https://domain_name.com/ 提供服务。请求通过 NGINX 反向代理处理到端口 3000。
我现在在端口 3001 上运行了第二个应用程序;两个实例都在 PM2 中运行。 通过https://domain_name.com/cards/ 到达第二个应用程序。
当访问此地址时,它会按预期传递第一页。但是,当发出 POST 请求时。地址https://domain_name.com/cards/api_route/。浏览器中的控制台显示 404 错误。但是,这在 Localhost 节点实例上运行良好。
我的启用站点的“默认”文件包含以下位置块。
HTTPS — proxy all requests to the Node app
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain_name.com;
# Use the Let’s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/domain_name.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain_name.com/privkey.pem;
# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
location /card {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3001/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
但是路径对于 api 路由是正确的
【问题讨论】:
标签: node.js reverse-proxy digital-ocean nginx-config