Last active
May 10, 2018 13:09
-
-
Save fornit1917/adc1a75df890797ea14769f7e8fe240d to your computer and use it in GitHub Desktop.
Nginx proxy config example (not php)
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
upstream app_backend { | |
server 127.0.0.1:8901; | |
keepalive 64; | |
} | |
# redirect from http to https | |
server { | |
listen *:80; | |
server_name example.com www.example.com; | |
location / { | |
rewrite ^(.*)$ https://example.com$1 permanent; | |
} | |
} | |
# redirect from https://www to https:// | |
server { | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
server_name www.example.com; | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; | |
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; | |
return 301 https://example.com$request_uri; | |
} | |
# main config | |
server { | |
#listen 80; | |
#listen [::]:80; | |
server_name example.com; | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; | |
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; | |
root /path/to/webroot; | |
index index.html index.htm; | |
location / { | |
try_files $uri @backend; | |
} | |
location @backend { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_max_temp_file_size 0; | |
proxy_pass http://app_backend; | |
proxy_redirect off; | |
proxy_read_timeout 240s; | |
} | |
location ~* /\.git { | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment