Last active
May 24, 2020 12:08
-
-
Save encoreshao/4f3e5b88e69ec1146f667a2bc139ff8f to your computer and use it in GitHub Desktop.
How to setup Nginx for react application - linktr.cn
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
server { | |
listen 80; | |
server_name linktr.cn; | |
include snippets/letsencrypt.conf; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
server_name linktr.cn; | |
ssl_certificate /..../fullchain.pem; | |
ssl_certificate_key /..../privkey.pem; | |
ssl_trusted_certificate /..../chain.pem; | |
include snippets/ssl.conf; | |
include snippets/letsencrypt.conf; | |
root /var/www/production/linktr-web; | |
index index.html; | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to redirecting to index.html | |
try_files $uri $uri/ /index.html; | |
} | |
# Media: images, icons, video, audio, HTC | |
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { | |
expires 1M; | |
access_log off; | |
add_header Cache-Control "public"; | |
} | |
# Javascript and CSS files | |
location ~* \.(?:css|js)$ { | |
try_files $uri =404; | |
expires 1y; | |
access_log off; | |
add_header Cache-Control "public"; | |
} | |
location ~ ^.+\..+$ { | |
try_files $uri =404; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment