Created
September 14, 2019 08:09
-
-
Save JSeam2/8871a640288a07688944c8a114fdd197 to your computer and use it in GitHub Desktop.
Example Nginx Conf to redirect http to https
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
# Redirect to HTTPS | |
server { | |
listen 80; | |
server_name example.com www.example.com; | |
return 301 https://$server_name$request_uri; | |
} | |
server { | |
listen 443; | |
server_name example.com www.example.com; | |
ssl on; | |
ssl_certificate /etc/nginx/ssl/cert.pem; | |
ssl_certificate_key /etc/nginx/ssl/cert_key.key; | |
client_max_body_size 20m; | |
proxy_read_timeout 600s; | |
location / { try_files $uri @app; } | |
location @app { | |
include uwsgi_params; | |
# Replace this, this depends on how you configure the app | |
uwsgi_pass unix:/tmp/app_socket.sock; | |
uwsgi_read_timeout 600s; | |
uwsgi_send_timeout 600s; | |
} | |
location /static { | |
alias /var/your_static_files_on_server; | |
} | |
location /media { | |
set $s3_bucket 's3-bucket-name.s3.amazonaws.com'; | |
set $url_full '$1'; | |
proxy_http_version 1.1; | |
proxy_set_header Host $s3_bucket; | |
proxy_set_header Authorization ''; | |
proxy_hide_header x-amz-id-2; | |
proxy_hide_header x-amz-request-id; | |
proxy_hide_header Set-Cookie; | |
proxy_ignore_headers "Set-Cookie"; | |
proxy_buffering off; | |
proxy_intercept_errors on; | |
# use google dns | |
resolver 8.8.4.4 8.8.8.8 valid=300s; | |
resolver_timeout 10s; | |
proxy_pass http://$s3_bucket$url_full; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment