Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I am using settings below in nginx and my Wordpress installation was using url rewrite rules in Apache. (e.g. permalinks like example.com/blog/2012/hello-world)

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, example.com/blog (home page) works fine.

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

server {
    listen   80;

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

    server_name 192.34.59.214;

    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 127.0.0.1:9$
    location ~ \.php$ {
            #fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}
share|improve this question

1 Answer 1

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

 
discard

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.