Skip to content

Instantly share code, notes, and snippets.

@parag60288
Last active May 7, 2020 15:04
Show Gist options
  • Save parag60288/525046f8b55f18142b16b60749ca891c to your computer and use it in GitHub Desktop.
Save parag60288/525046f8b55f18142b16b60749ca891c to your computer and use it in GitHub Desktop.
Nginx virtual host snippets, ssl configuration & some useful commands
## VHost for www.example.com without ssl, without proxy, without redirect
server {
listen 80;
server_name www.example.com;
location / {
root html/example.com;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
## VHost for example.com without ssl, without proxy, without redirect
server {
listen 80;
server_name example.com;
location / {
root html/example.com;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
## VHost for www.example.com without ssl, with proxy, without redirect
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass https://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
## VHost for example.com without ssl, with proxy, without redirect
server {
listen 80;
server_name example.com;
location / {
proxy_pass https://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
## VHost for www.example.com with ssl, without proxy, without redirect
server {
listen 80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.example.com;
location / {
root html/example.com;
index index.html index.htm;
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# ssl on;
ssl_certificate /<PATH_TO_SSL>/www.example.com/fullchain.pem;
ssl_certificate_key /<PATH_TO_SSL>/www.example.com/privkey.pem;
}
## VHost for example.com with ssl, without proxy, without redirect
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com;
location / {
root html/example.com;
index index.html index.htm;
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# ssl on;
ssl_certificate /<PATH_TO_SSL>/www.example.com/fullchain.pem;
ssl_certificate_key /<PATH_TO_SSL>/www.example.com/privkey.pem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment