I'm serving wordpress behind a reverse proxy in nginx. I want to be able to serve also static pages that I have in a different root directory.
I tried this:
server {
listen 80;
listen [::]:80;
server_name ${NGINX_HOST};
root /static-pages;
sendfile on;
tcp_nodelay on;
location / {
try_files $uri $uri/ /static-pages/ =404;
#try_files $uri $uri/ =404;
#try_files /static-pages $uri/ =404;
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;
proxy_pass http://wordpress;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
The wordpress works good but when I try to reach one of the static pages, I keep getting 404.
Of course I can add a location
directive to each static page I have but this seems like an overhead. Can I make it work somehow?
Here's a part of the debug log which I think is relevant:
[debug] 7#7: *2 generic phase: 12
[debug] 7#7: *2 try files handler
[debug] 7#7: *2 http script var: "/marketing-analyst"
[debug] 7#7: *2 trying to use file: "/marketing-analyst" "/static-pages/marketing-analyst"
[debug] 7#7: *2 http script var: "/marketing-analyst"
[debug] 7#7: *2 trying to use dir: "/marketing-analyst" "/static-pages/marketing-analyst"
[debug] 7#7: *2 try file uri: "/marketing-analyst"
Of course the directory /static-pages/marketing-analyst
exists.