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



我在端口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

这是这个答案和另一个答案的组合,因为AWS文档不断变化。

在EC2上,文件/etc/nginx/conf.d/elasticbeanstalk/00_application.conf是一个似乎附加在主nginx.conf文件上的文件,行为/etc/nginx/nginx.conf

然而

最新的文档说,工作目录中有.platform/nginx/conf.d/your_custom.conf才是真正的nginx扩展文件。

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

因此,我建议使用container_command方法,或者现在手动更改它。

最新更新