Home > Enterprise >  AWS Elastic Beanstalk - nginx configuration for python (3.7 on AL2) flask app
AWS Elastic Beanstalk - nginx configuration for python (3.7 on AL2) flask app

Time:12-06

I am trying to get a simple flask (python) app running on elastic beanstalk with an nginx server.

The python app appears to start up ok with the following config in my .ebextensions application.config:

option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: application:application

gunicorn appears to bind itself ok to the app - see:

Nov 30 07:40:00 ip-172-31-19-88 web: [2021-11-30 07:40:00  0000] [32041] [INFO] Starting gunicorn 20.1.0
Nov 30 07:40:00 ip-172-31-19-88 web: [2021-11-30 07:40:00  0000] [32041] [INFO] Listening at: http://127.0.0.1:8000 (32041)
Nov 30 07:40:00 ip-172-31-19-88 web: [2021-11-30 07:40:00  0000] [32041] [INFO] Using worker: gthread
Nov 30 07:40:00 ip-172-31-19-88 web: [2021-11-30 07:40:00  0000] [32098] [INFO] Booting worker with pid: 32098

When I visit the web url, the browser just hangs for a long time (minutes) and eventually times out with "took too long to respond".

I believe it has something to do with the NGINX config not proxy'ing the requests correctly - so I've tried adding the following to .ebextensions/nginx/conf.d/myconf.conf

server {
      location / {
          proxy_pass          http://127.0.0.1:8000;
          proxy_http_version  1.1;
          proxy_set_header    Connection          $connection_upgrade;
          proxy_set_header    Upgrade             $http_upgrade;
          proxy_set_header    Host                $host;
          proxy_set_header    X-Real-IP           $remote_addr;
          proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
      }
}

but that doesn't appear to do anything.

Any ideas on what the issue could be? I'm not sure its NGINX but it does appear to be at that layer where the issue is occuring... the web server doesn't appear to know what to do with my web request.

Thanks for your help.

CodePudding user response:

.ebextensions/nginx/conf.d/myconf.conf is incorrect path. On AL2, nginx should be customized using .platform/nginx/conf.d/ or .platform/nginx/nginx.conf if you are overwriting entire nginx.conf.

  • Related