Change WordPress root directory in nginx

Mostafa Soufi asked:

I have a website that address is and also a WordPress that is I would change the WordPress root directory in the nginx.

here is my config:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

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

    server_name localhost;

    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/html;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

    location /blog/ {
        root /var/www/blog;

I getting the below error when I open

404 Not Found

nginx/1.14.0 (Ubuntu)

My answer:

sudo mv /var/www/blog /var/www/html/blog

Keep your directory structure simple. Don’t move things outside the defined document root unless you have an actual good technical reason to do so, because it makes configuring the web server a nightmare.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.