Skip to content

Instantly share code, notes, and snippets.

@johanneslamers
Last active September 3, 2020 17:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanneslamers/f6d2bc0d7435dca130fc to your computer and use it in GitHub Desktop.
Save johanneslamers/f6d2bc0d7435dca130fc to your computer and use it in GitHub Desktop.
Craft CMS Nginx config for Laravel Forge with locale support
server {
listen 80 default_server;
server_name default;
root /home/forge/default/public;
# FORGE SSL (DO NOT REMOVE!)
# ssl on;
# ssl_certificate;
# ssl_certificate_key;
index index.html index.htm index.php;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SERVER_NAME $http_host;
}
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
}
location / {
try_files $uri $uri/ @rewrites;
}
location @enrewrites {
rewrite ^/en/(.*)$ /en/index.php?p=$1? last;
}
location /en/ {
try_files $uri $uri/ @enrewrites;
}
#location ~ ^(.*)$ {
# try_files $uri $uri/ /index.php?p=$uri&$args;
#}
location ~* (?:^|/)\. {
deny all;
}
location ~* (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
deny all;
}
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
try_files $uri /index.php?$query_string;
expires -1;
access_log /var/log/nginx/example.com-access.log;
}
location ~* \.(?:rss|atom)$ {
try_files $uri /index.php?$query_string;
expires 1h;
add_header Cache-Control "public";
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
try_files $uri /index.php?$query_string;
expires 1M;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)$ {
try_files $uri /index.php?$query_string;
expires 1y;
add_header Cache-Control "public";
}
location ~* \.(?:ttf|ttc|otf|eot|woff)$ {
try_files $uri /index.php?$query_string;
expires 1M;
add_header Cache-Control "public";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment