Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The v2.Statamic part of nginx.conf file on forge.laravel.com
...
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/server/*;
# For legacy URL redirect with query parameters
# - create a file called "legacy-redirect.map" with a new line for each redirect
# - example line: /old-url/with?query /new-url/without-a-query;
# - Add the following BEFORE the server block, update the path and uncomment the include line
map $uri$is_args$args $new_uri {
default 0;
# include /home/forge/example.com/legacy-redirects.map;
}
# Start selecting and copying below
#################################################
# Edit path below
error_log /var/log/nginx/dev.hammickeditions.com-error.log error;
# If a redirect (from map above)
if ($new_uri) {
return 301 $new_uri;
}
# Start: Statamic specific
# Dynamically set the try_files locations.
# Statically cached files should only be loaded for GET requests.
set $try_files @default;
if ($request_method = GET) {
set $try_files @static;
}
# The files to try when its a potentially static cache request (ie. a GET request)
# static_caching_ignore_query_strings: false
# location @static {
# try_files /static${uri}_${query_string}.html @default;
# }
# static_caching_ignore_query_strings: true
location @static {
try_files /static${uri}_.html @default;
}
# The files to try when it's not a static cache request (ie. anything other than GET)
location @default {
try_files $uri $uri/ /index.php?$query_string;
}
location / {
try_files $uri $try_files; # Use the dynamically assigned locations from above.
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# Block access to hidden files (except the /.well-known/ dir)
location ~ /(?!.well-known)(\.)\w+ {
deny all;
return 404;
}
# Block access to Statamic, content, and cache locations
location ~ ^\/(statamic|local|(site\/(?!themes))) {
deny all;
return 404;
}
# Enable gzip compression
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
# Expire headers on static assets
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff2)$ {
try_files $uri /index.php?$query_string;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
try_files $uri /index.php?$query_string;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
#################################################
# End selecting and copying above:
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/after/*;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment