Skip to content

Instantly share code, notes, and snippets.

@orlissenberg
Last active August 29, 2015 14:26
Show Gist options
  • Save orlissenberg/a8cc04f320aa61259c16 to your computer and use it in GitHub Desktop.
Save orlissenberg/a8cc04f320aa61259c16 to your computer and use it in GitHub Desktop.
Nginx PHP configuration example.
# http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
# http://laravel-recipes.com/recipes/26/creating-a-nginx-virtualhost
server {
listen 80;
server_name www.sitename.dev sitename.dev;
charset utf-8;
access_log /var/log/nginx/sitename.access.log;
error_log /var/log/nginx/sitename.error.log;
root /srv/www/sitename/public;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location ~ \.php$ {
# Defines a regular expression that captures a value for the $fastcgi_path_info variable.
# The regular expression should have two captures: the first becomes a value of the
# $fastcgi_script_name variable, the second becomes a value of the $fastcgi_path_info variable.
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
include /etc/nginx/fastcgi_params;
try_files $uri =404; # This is not needed if you have cgi.fix_pathinfo = 0 in php.ini (you should!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment