Skip to content

Instantly share code, notes, and snippets.

@husa
Last active August 1, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save husa/f98cefa0125a0afea3b77183a555dc51 to your computer and use it in GitHub Desktop.
Save husa/f98cefa0125a0afea3b77183a555dc51 to your computer and use it in GitHub Desktop.
nginx config for serving static site(browser history) + reverse proxy + redirect http to https
# TODO
# 1. MAJOR: create 404.html and 5xx.html error pages and bundle them with the app
# 2. MINOR: remove trailing slash (app will handle it okay)
server {
listen 80;
server_name localhost;
root /usr/src/app;
index index.html;
# redirect http to https
# if ($http_x_forwarded_proto != 'https') {
# return 301 https://$host$request_uri;
# }
# error_page 404 /404.html;
# error_page 500 501 502 503 504 /5xx.html;
# remove .html extension
if ($request_uri ~* ^/(.*)\.html$) {
rewrite ^/(.*)\.html$ $1 permanent;
}
# disable caching for specific extensions
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
# force caching for css/js files
location ~* \.(?:css|js)$ {
try_files $uri =404;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# any route with file extension(containing dot)
location ~ ^.+\..+$ {
try_files $uri =404;
}
location / {
try_files $uri $uri/ /index.html;
}
#location ^~ /api {
# proxy_pass http://api-server:1234;
# }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment