Skip to content

Instantly share code, notes, and snippets.

@rkamradt
Created June 22, 2020 21:53
Show Gist options
  • Save rkamradt/a9f15e13166945b7d9c57555a5774c3c to your computer and use it in GitHub Desktop.
Save rkamradt/a9f15e13166945b7d9c57555a5774c3c to your computer and use it in GitHub Desktop.
Nginx configuration that works with React routes
worker_processes auto;
events {
worker_connections 8000;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
index index.html index.htm;
# different things to try for locations that begin with /
location / {
try_files $uri $uri/ /index.html;
}
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";
}
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