404 on WordPress sub-directory /blog post and categories permalink url

connor00

New Member
YetiShare User
YetiShare Supporter
Sep 29, 2018
4
3
3
29
Want to use WordPress blog on sub-directory ( /blog) URL but post and categories permalink URL showing 404 not found

used this Nginx config

Code:
location /blog/ {

    index index.php;

    try_files $uri $uri/ /blog/index.php?$args;

}
but instead of page opening every .php file under /blog downloading in the browser :( here is my current Nginx config please help currently I am using yetishare file sharing script in the main domain but want to use WordPress /blog in sub-directory

current Nginx config


Code:
server {
    listen      ***:443 ssl http2;
    server_name devdrive.cloud www.devdrive.cloud;
    root        /home/admin/web/devdrive.cloud/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/devdrive.cloud.log combined;
    access_log  /var/log/nginx/domains/devdrive.cloud.bytes bytes;
    error_log   /var/log/nginx/domains/devdrive.cloud.error.log error;

    ssl_certificate      /home/admin/conf/web/devdrive.cloud/ssl/devdrive.cloud.pem;
    ssl_certificate_key  /home/admin/conf/web/devdrive.cloud/ssl/devdrive.cloud.key;
    ssl_stapling on;
    ssl_stapling_verify on;

    include /home/admin/conf/web/devdrive.cloud/nginx.hsts.conf*;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ /\.(?!well-known\/) {
        deny all;
        return 404;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
        location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
            expires 30d;
            fastcgi_hide_header "Set-Cookie";
        }
        
        location ~* /(?:uploads|files)/.*.php$ {
            deny all;
            return 404;
        }
        
        location ~ [^/]\.php(/|$) {
            if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            try_files $uri =404;
            fastcgi_pass unix:/run/php/php8.0-fpm-devdrive.cloud.sock;
            fastcgi_index index.php;
            include        fastcgi_params;
            include /etc/nginx/fastcgi_params;
            fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
            include /home/admin/conf/web/devdrive.cloud/nginx.fastcgi_cache.conf*;
            if ($request_uri ~* "/wp-admin/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
                set $no_cache 1;
            }
            if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
                set $no_cache 1;
            }
        }
    }

     #location / {
        if (!-e $request_filename) {
            rewrite ^/(.*) /index.php?_page_url=$1 last;
        }
     #}

    location /files/ {
        internal;
    }

    # these locations would be hidden by .htaccess normally
    location /logs/ {
        deny all;
    }

    location /error/ {
        alias   /home/admin/web/devdrive.cloud/document_errors/;
    }

    location /vstats/ {
        alias   /home/admin/web/devdrive.cloud/stats/;
        include /home/admin/web/devdrive.cloud/stats/auth.conf*;
    }

    proxy_hide_header Upgrade;

    include /etc/nginx/conf.d/phpmyadmin.inc*;
    include /etc/nginx/conf.d/phppgadmin.inc*;
    include /home/admin/conf/web/devdrive.cloud/nginx.ssl.conf_*;
}