Skip to content

Instantly share code, notes, and snippets.

@smotesko
Created April 1, 2014 08:18
Show Gist options
  • Save smotesko/9910008 to your computer and use it in GitHub Desktop.
Save smotesko/9910008 to your computer and use it in GitHub Desktop.
My NGINX config
server {
listen 80 default;
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
index index.html index.htm;
server_name _;
set $hst $host;
if ($host ~ www\.(.*)) { set $hst $1; }
location / {
root /var/www/$hst/web;
try_files $uri @php-fcgi;
}
location @php-fcgi {
rewrite ^(.*) /index.php last;
}
location ~ \.php($|/) {
set $script $uri;
set $path_info "";
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$hst/web$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
#SCRIPT_NAME needs to remain without the document_root on front
#Otherwise PHP_SELF breaks, the interpreter will still find the file
#because of the added SCRIPT_FILENAME parameter below
#This one was added right into the file, since with root moved, and path_info split
#It should no longer need to be set manually for each virtual host
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
#fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
#the two lines below are possible now because of the fastcgi_split_path_info function
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
# I removed the version, as not to give away too much information
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $http_host;
fastcgi_param DOCUMENT_ROOT /var/www/$hst/web;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment