Created
September 1, 2020 01:54
-
-
Save Alex3917/de07c7e181b61133662af5c76d3ea869 to your computer and use it in GitHub Desktop.
How to configure nginx for ElasticBeanstalk with Python on Amazon Linux 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
user nginx; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; # increase if you have lots of clients | |
accept_mutex off; # set to 'on' if nginx worker_processes > 1 | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log combined; | |
sendfile on; | |
server_tokens off; | |
map $http_upgrade $connection_upgrade { | |
default "upgrade"; | |
} | |
server { | |
listen 80; | |
# Replace these with the actual values needed | |
server_name WWW.YOURDOMAINNAME.COM YOURDOMAINNAME.COM; | |
client_max_body_size 150m; | |
root /var/app/current; | |
location / { | |
try_files $uri @proxy_to_app; | |
} | |
location @proxy_to_app { | |
proxy_pass http://127.0.0.1:8000; | |
proxy_redirect off; | |
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; | |
# This assumes your load balancer only accepts HTTPS traffic, and blocks all other traffic. If so, then you can forward the traffic | |
# coming into your ALB on port 443 to your instance on port 80, and tell the instance that it was encrypted. | |
proxy_set_header X-Forwarded-Proto https; | |
add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET, POST, PUT, DELETE'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization'; | |
} | |
client_header_timeout 60; | |
client_body_timeout 60; | |
keepalive_timeout 60; | |
gzip off; | |
gzip_comp_level 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment