Last active
August 1, 2018 12:07
-
-
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
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
# 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