多节点实例,NGINX反向代理,服务页面,发布请求时出现404错误?

问题描述 投票:0回答:1

所以我的堆栈在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
1个回答
0
投票

问题已解决。...

位置块

位置/卡{

需要

位置/卡/ {

先前搜索https://domain_name.com/cards

已交付页面和:

https://domain_name.com/cards/

返回的错误:无法获取//

© www.soinside.com 2019 - 2024. All rights reserved.