Skip to content

Instantly share code, notes, and snippets.

@zackad
Created July 1, 2020 10:39
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zackad/7dd46be60df4fe7d1010a0fcf33d1afc to your computer and use it in GitHub Desktop.
Save zackad/7dd46be60df4fe7d1010a0fcf33d1afc to your computer and use it in GitHub Desktop.
NGINX server configuration for nextjs static generated site.
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location ~ /.+ {
try_files $uri $uri.html $uri =404;
}
location / {
index index.html index.htm;
}
error_page 404 /_errors/404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
@Flowkap
Copy link

Flowkap commented Jun 28, 2021

Thx man :) Was looking for exactly this (location dependant try_files + error 404 on not available page)

@RileyMShea
Copy link

+1 works great, thanks for the gist

@kyung-lee-official
Copy link

You saved my life! ♥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment