I'm trying to get my Wordpress blog hosted on blog.domain.com
to work on domain.com/blog
.
I have been able to do this with proxy_pass
successfully but the issue is certain scripts such as the login page for admins (/wp-login.php) does not work - it gives me File not found.
. I have isolated the issue to my Laravel applications FastCGI setup in my Nginx configuration. When I comment it out, my blog works but then my Laravel app is inaccessible. I've been trying different configurations but I have little knowledge with Nginx.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mydomain.com;
server_tokens off;
root /home/appfolder/mydomain.com/public;
...
...
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# WHEN I COMMENT OUT THIS BLOCK, BLOG WORKS BUT LARAVEL BREAKS
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm-mydomain.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /blog {
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass https://blog.mydomain.com;
}
location /blog/wp-content {
proxy_pass https://blog.mydomain.com/wp-content;
}
location /blog/wp-includes {
proxy_pass https://blog.mydomain.com/wp-includes;
}
location /blog/wp-content/uploads {
proxy_pass https://blog.mydomain.com/wp-content/uploads;
}
location /blog/wp-login.php {
proxy_pass https://blog.mydomain.com/wp-login.php;
}
location /blog/wp-admin {
proxy_pass https://blog.mydomain.com/wp-admin;
}
location /bitnami {
proxy_pass https://blog.mydomain.com/bitnami;
}
location /mod_pagespeed_beacon {
proxy_pass https://blog.mydomain.com/mod_pagespeed_beacon;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/mydomain.com-error.log error;
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
}
...
Hosted on an Ubuntu server managed by Laravel Forge. Any ideas?
Update: As per Richards answer, I have started getting it working a little bit but I need to add rules for all files which doesn't seem efficient.
I'm trying to get all .PHP files related to Wordpress (after /blog/
) to be forwarded to the proxy. I have tried:
location ~ /blog/wp-admin/(\d+) {
add_header X-debug-message "$1";
proxy_pass https://blog.mydomain.com/wp-admin/$1;
}
But this doesn't seem to work.