Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonmccallister/9693258 to your computer and use it in GitHub Desktop.
Save jasonmccallister/9693258 to your computer and use it in GitHub Desktop.
Nginx conf files for Craft and Laravel 4 servers. As seen on http://phawk.co.uk/blog/laravel-4-nginx-config/
# Don't throw any errors for missing favicons and don't display them in the logs
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Don't log missing robots or show them in the nginx logs
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# Any files matching these extensions are cached for a long time
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires max;
add_header Cache-Control public;
access_log off;
}
server {
# Force non-www version of the site
listen 80;
server_name www.DOMAINNAME;
return 301 http://DOMAINNAME$request_uri;
}
server {
listen 80;
server_name DOMAINNAME;
root /var/www/DOMAINNAME/public; # Laravels public folder
access_log /var/www/DOMAINNAME/logs/nginx.access.log;
error_log /var/www/DOMAINNAME/logs/nginx.error.log;
autoindex on;
index index.php;
# Cache static files for a long time
include global/static-asset-caching.conf;
# Pull in some good PHP defaults
include global/php-restrictions.conf;
location / {
# First try and load files from the public folder, if they don't exist
# then send the request through to laravel
try_files $uri $uri/ /index.php;
# Forward requests on to PHP-FPM
location = /index.php {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
# If someone explicitly tries to load a PHP file return a 404 error,
# always use url rewrites and never have the .php extension in the url
location ~ \.php$ {
return 404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment