1

I'm running an Express server on port 5000 and a React app on 8080.

My idea was to just direct traffic based on location (uri), but I've been getting a duplicate location "/" error with this partial insert into the AWS Beanstalk ngnix config:

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;
}

This gets included in a standard ngnix.conf which looks roughly like this: https://gist.github.com/alextanhongpin/00da7f551969f052e57f3c4dcd9ac4b0

A13X
  • 409
  • 1
  • 6
  • 27

1 Answers1

1

This is some combination of this answer and this other one since AWS documentation keeps changing.

On EC2, the file /etc/nginx/conf.d/elasticbeanstalk/00_application.conf is the file that appears to get appended on the main nginx.conf file with the line /etc/nginx/nginx.conf.

HOWEVER

The latest documentation says having .platform/nginx/conf.d/your_custom.conf in your working directory is the real nginx extension file.

I had to manually change 00_application.conf on EC2 in order for the duplicate error to go away, it appears this file stayed default even when redeploying with the custom config files, and that file happens to have a location / {}.

So I would recommend the container_command method or manually changing it for now.

A13X
  • 409
  • 1
  • 6
  • 27
  • I would further recommend reading up on changes to Amazon Linux 2 (AL2), it's a new setup: https://aws.amazon.com/blogs/compute/introducing-a-new-generation-of-aws-elastic-beanstalk-platforms/ – A13X Dec 30 '20 at 20:21
  • You can also remove the 00_application.conf in a `.platform/hooks/predeploy` script as well, mine just had a default location block in it. – A13X Dec 31 '20 at 02:58
  • Based on the doc for AL2, we should be able to override the entire conf, but it says to include the conf.d files. So something like returning 301 for http on / now doesn't work? Is this by design, and we must remove the conflicting file with a script? – Half_Duplex Feb 18 '21 at 19:54
  • I haven't tried a *full* replacement (`.platform/nginx/nginx.conf`) as AL2 mentions. I'm currently using `location.conf` to set `/` and another path. Do let us know if you get full config replacement working without a script, I think I was originally trying to do that but it wasn't working for some reason. – A13X Mar 07 '21 at 08:00
  • 1
    I just replaced the entire config, and also found I needed to rebuild the EC2 env. It seems when you're trying different things, moving files around, some of those config files stick and are used to config the proxy when you don't intend for them to. – Half_Duplex Mar 10 '21 at 17:10