Skip to content

Instantly share code, notes, and snippets.

@Amar-Chaudhari
Created July 6, 2016 12:47
Show Gist options
  • Save Amar-Chaudhari/773928fdef2958a6ce95ffba8d5a7e79 to your computer and use it in GitHub Desktop.
Save Amar-Chaudhari/773928fdef2958a6ce95ffba8d5a7e79 to your computer and use it in GitHub Desktop.
Nginx configuration for Wordpress blog on subdirectory

Nginx configuration

WordPress single site rule Blog running on - /blog/ Example : www.xyz.com/blog

Filename : xyz.com

server {
     listen  80;
     server_name xyz.com;
     access_log /var/webapps/xyz.com/logs/access.log;
     error_log /var/webapps/xyz.com/logs/error.log;

     root /var/webapps/xyz.com/public_html/;
     index index.php index.html index.htm;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
            root /var/webapps/sbprod/SBWebsite/main/;
    }

    # Blog related config in file.
    include global/wordpress.conf;
}

Filename : wordpress.conf

# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location /blog/ {
	try_files $uri $uri/ /blog/index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
	fastcgi_split_path_info ^(.+?\.php)(/.*)$;
	if (!-f $document_root$fastcgi_script_name) {
		return 404;
	}
	# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)

	include fastcgi_params;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	fastcgi_pass    127.0.0.1:9000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment