Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of a default server configuration for Nginx (sites-available/default).
server {
listen 80 default; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
# Make site accessible from http://localhost/
server_name localhost;
server_name_in_redirect off;
charset utf-8;
access_log /usr/share/nginx/access.log;
error_log /usr/share/nginx/error.log;
root /usr/share/nginx/www;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then trigger 404
try_files $uri $uri/ =404;
server_name_in_redirect off;
# pass the PHP scripts to FPM socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /usr/share/nginx/www;
# send bad requests to 404
fastcgi_intercept_errors on;
include fastcgi_params;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment