Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have installed nginx and Wordpress on my server. However, my blog is not in domain root. (e.g. and contents are in /var/www/

I am using settings below in nginx and my Wordpress installation was using url rewrite rules in Apache. (e.g. permalinks like

However, interestingly, all these URL rewrite rules go into index.php in / (not in blog/). I want to fix that but I could not figure out how. Another interesting thing is, (home page) works fine.

For example, I guess since is not a real file, try_files is executing (The url is remains same but that index.php gets executed). Any help is appreciated!

server {
    listen   80;

    root /var/www/;
    index index.php;


    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /usr/share/nginx/www;

    # pass the PHP scripts to FastCGI server listening on$
    location ~ \.php$ {
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
share|improve this question
up vote 2 down vote accepted

You need another location section for WordPress.

location /blog/ {
    try_files $uri $uri/ /blog/index.php
share|improve this answer
Thanks Michael, you are my nginx hero! – Ahmet Alp Balkan Feb 14 '13 at 3:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.