-1

I have a website that address is site.com and also a WordPress that is site.com/blog. 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;
    server_name site.com www.site.com;

    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 site.com/blog

404 Not Found

nginx/1.14.0 (Ubuntu)

3 Answers3

3
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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
1

You need to add try_files $uri $uri/ /index.php?q=$uri$args; to your location /blog block so that nginx knows which files to look in that location.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
1

try this and it will fix your problem

location /blog {
        root /var/www;
        index index.php index.html;
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
                proxy_intercept_errors on;
                fastcgi_index index.php;
                fastcgi_intercept_errors on;
                include fastcgi_params;

        }
Arash Shams
  • 81
  • 1
  • 4