WordPress url rewrite on nginx when wordpress is not in the main directory

For some reason I always have trouble getting WordPress to work on nginx.

I have my WordPress installation in the folder “site” (inside public_html).
This is my nginx configuration:

Read More
server {
    server_name www.wouterds.be wouterds.be;
    access_log /srv/www/www.wouterds.be/logs/access.log;
    error_log /srv/www/www.wouterds.be/logs/error.log;

    location / {
        root /srv/www/www.wouterds.be/public_html;
        index index.php index.html index.htm;
        try_files $uri $uri/ /site/index.php?$args;
        autoindex on;
    }

   location ~ .php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/www.wouterds.be/public_html$fastcgi_script_name;
    }
}

When I visit my website http://wouterds.be/ I get just the directory index.
When I visit http://wouterds.be/blog/ I get the right page and everything is working.
But I have no idea how to get it work on the base url.

Anyone who can help me out a bit? I’m certainly not an nginx expert and after 4 hours Google-ing I decided to give it a try here.

Related posts

Leave a Reply

2 comments

  1. Just change:

        root /srv/www/www.wouterds.be/public_html;
    

    to

        root /srv/www/www.wouterds.be/public_html/site;
    

    assuming wordpress index.php is inside site folder.

    Also move root line outside & above location block.

    You can try…

    server {
      #other stuff 
    
        root /srv/www/www.wouterds.be/public_html/site ;
    
        location / {
            root /srv/www/www.wouterds.be/public_html;
            index index.php index.html index.htm;
            try_files $uri $uri/ /site/index.php?$args;
            autoindex on;
        }
    
      #other stuff 
    }