Hello all. Hope you are doing well today. So I have set up my WordPress website in a subdirectory of my domain (/blog) and is hosted in a VPS with Nginx as reverse proxy. Everything is working fine except while I’m trying to access a post. Right now when I try to access posts I get Nginx’s 404 Not Found page.
I have looked for solutions online and each and every solution says to put
>try\_files $uri $uri/ /blog/index.php?$args;
in the location block but it’s not working after doing so.
What could be the reason for this? Am I doing something wrong? Here’s my website’s Nginx config file:
​
server {
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
server_name www.example.com;
# Web App
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection ‘upgrade’;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
# WordPress Blog
location /blog {
access_log /var/log/nginx/blog_access.log;
error_log /var/log/nginx/blog_error.log;
root /var/www/html/example.com;
index index.php;
# Add a trailing slash if missing
if (!-f $request_filename) {
rewrite [^/]$ $uri/ permanent;
}
# try_files $uri $uri/ /blog/index.php?q=$uri&$args;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
# Change this to your fpm socket
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
}
Any help would be highly appreciated. Thanks
[ad_2]