Configuring WordPress Blog as sub-directory alongside Django in Nginx

Using regular expressions within Nginx we can bind urls to particular application servers, below we will configure wordpress blog and django site to be deployed on same domain name with each having their respective application servers i.e. ‘fastcgi’ for wordpress and ‘uwsgi’ for django.

Short introduction on how nginx configuration works:

Consider the following basic configuration:

server {
    listen 80;
    server_name djangoproject.com;
    location /foo {
        uwsgi_pass unix:///home/django_site.sock;
        include uwsgi_params;
        }
}

Django site is running using uwsgi app server, so django_site.sock is created at /home/ directory. When we hit djangoproject.com/foo then nginx looks for location block matching ‘foo’ string and serves the request with uwsgi.

So by replacing ‘foo’ with ‘blog’ and uwsgi server with fastcgi, nginx serves wordpress blog.

Configuration: django and wordpress blog on same domain:

Domain: micropyramid.com

Django project directory: /home/micropyramid/micropyramid
Uwsgi sock file location: /home/micropyramid/mp.sock

Wordpress project directory: /var/www/html
Fastcgi sock file location: /var/run/php5-fpm.sock

server {
    listen 80;
    server_name micropyramid.com;
    location / {
        uwsgi_pass  unix:///home/micropyramid/micropyramid.sock;
        include     uwsgi_params;
    }
    location /blog {
        root /var/www/html;
        index index.php index.html index.htm;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        unix:/var/run/php5-fpm.sock;
        index.php;
        fastcgi_params;
    }
}

When the url contains the format ‘micropyramid.com/blog’ nginx matches location with /blog regex and uses fastcgi to serve wordpress blog, on all other cases django site will be served.

Posted On 19 October 2014 By MicroPyramid


Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
How to deploy django with uwsgi and nginx using Ansible play book.

Ansible is a scripting language mostly used to automate installing applications, deploying apps etc..
Why Ansible:
You may think why learn new language if I ...

Continue Reading...
ELK Stack for Parsing your Logs- Part 2

In Previous Tutorial we looked into Setting up EL Server which can ingest your Syslog files. In this Post, you will learn about pushing your ...

Continue Reading...
How to setup http password authentication with nginx

HTTP Authentication is used to allow access limit to a site or particular directories by validating the username and password. HTTP basic authentication can also ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties