重复位置“/”Nginx 错误后端和前端

Duplicate Location "/" Nginx Error Backend And Frontend

我是 运行 端口 5000 上的 Express 服务器和端口 8080 上的 React 应用程序。

我的想法是只根据位置 (uri) 引导流量,但我一直在将此部分插入到 AWS Beanstalk ngnix 配置中时遇到重复位置“/”错误:

location / {
  root                /var/app/current/build/;
  try_files           $uri /index.html;
  proxy_http_version  1.1;
  proxy_pass          http://127.0.0.1:8080/;
  proxy_set_header    Host $host;
  proxy_set_header    X-Real-IP $remote_addr;
  proxy_set_header    Connection $connection_upgrade;
  proxy_set_header    Upgrade $http_upgrade;
  proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /socket-io {
  proxy_pass                http://127.0.0.1:5000/;
  proxy_set_header          Host $host;
  proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header          X-NginX-Proxy true;
  proxy_set_header          X-Real-IP $remote_addr;
  proxy_ssl_session_reuse   off;
  proxy_cache_bypass        $http_upgrade;
}

这包含在标准 ngnix.conf 中,大致如下所示:https://gist.github.com/alextanhongpin/00da7f551969f052e57f3c4dcd9ac4b0

这是 this answer and this other one 的某种组合,因为 AWS 文档不断变化。

在 EC2 上,文件 /etc/nginx/conf.d/elasticbeanstalk/00_application.conf 是似乎附加到主 nginx.conf 文件的文件,其中包含行 /etc/nginx/nginx.conf.

然而

latest documentation 表示在您的工作目录中有 .platform/nginx/conf.d/your_custom.conf 是真正的 nginx 扩展文件。

我不得不在 EC2 上手动更改 00_application.conf 以使重复错误消失,即使使用自定义配置文件重新部署,该文件似乎仍保持默认状态,并且该文件恰好有一个 location / {}.

所以我会推荐 container_command 方法或暂时手动更改它。