views:

191

answers:

1

I have my main website and wordpress in different directories on my server on which I use nginx as the web server. The main website is in /home/me/www and Wordpress is in /home/me/wordpress. I need to have them in separate directories this way for a particular reason. How do I specify this in the nginx configuration file? I currently have the following and it does not work:

location / {
    root   /home/me/www;
    index  index.php index.html index.htm;
}

location /blog {
    root /home/me/wordpress;
    index index.php index.html index.htm;
}

location ~ \.php$ {
    set $php_root /home/me/www;
    if ($request_uri ~ /blog) {
        set $php_root /home/me/wordpress;
    }
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}

It currently returns HTTP 404 when I try to access http://mydomain/blog

+1  A: 

Check out this question and the Nginx Manual.

Try changing your blog line to:

location ^~ /blog/ {
    root /home/me/wordpress;
    index index.php index.html index.htm;
}
Nick Presta
Thanks for the answer! Actually, the question that you have pointed to is one that I had asked a long time back! I never got it to work based on the answer. Only today I got it to work. I've posted a comment on that answer.
ErJab