Skip to content

Instantly share code, notes, and snippets.

@encoreshao
Last active May 24, 2020 12:08
Show Gist options
  • Save encoreshao/4f3e5b88e69ec1146f667a2bc139ff8f to your computer and use it in GitHub Desktop.
Save encoreshao/4f3e5b88e69ec1146f667a2bc139ff8f to your computer and use it in GitHub Desktop.
How to setup Nginx for react application - linktr.cn
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