Sample NGINX config files

Many times NGINX conf reference comes handy. Here I am copying couple of NGINX conf setups for future reference.

Single WordPress

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        #server_name _;
        server_name example.com www.example.com;

        location / {
                #try_files $uri $uri/ =404;
                #try_files $uri/ index.php$args;
	        try_files $uri /index.php$is_args$args;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php7.0-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

	location /wp-admin/ {
		index index.php;
		try_files $uri $uri/ /index.php$args;
	}
}

WordPress multi site

Please not the additional details at top and before closing bracket of server block. For installation of multiple please check post How to Install WordPress Multisite

map $http_host $blogid {
    default 0;
    include /var/www/yourwebsite/wp-content/uploads/nginx-helper/map.conf;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        #server_name _;
        server_name example.com www.example.com;

        location / {
                #try_files $uri $uri/ =404;
                #try_files $uri/ index.php$args;
	        try_files $uri /index.php$is_args$args;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php7.0-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

	location /wp-admin/ {
		index index.php;
		try_files $uri $uri/ /index.php$args;
	}
	
	location ~ ^/files/(.*)$ {
	  try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
	  access_log off; log_not_found off; expires max;
	}

	location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
		expires 24h;
		log_not_found off;
	}

	location ^~ /blogs.dir {
		internal;
		alias /var/www/fintrekking/wp-content/blogs.dir ;
		access_log off; log_not_found off;      expires max;
	}


	if (!-e $request_filename) {
		rewrite /wp-admin$ $scheme://$host$uri/ permanent;
		rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
		rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
	}
	
}
CategoriesUncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *