Nginx Reverse proxy excluding files

eg flag

I've a landing page done using wordpress and is hosted on I've an app running on on external url. When user try to access wordpress files, it should be served from and if that url or folder is not available the url must be masked and must go to remote url as$1. I've tried using nginx reverse-proxy but it is not working.

location / {
    try_files $uri $uri/ /index.php?$query_string @proxy;

location @proxy {
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Michael Hampton avatar
cz flag
What is not working?
eg flag
If the files are not found it must go to proxy. currently it is going to 404 of wordpress. For example if I've searched then the files need to be served from external domain but url must be shown as
us flag

The try_files only checks if actual files exist on filesystem. Once it founds a file that exists, it uses that one to serve a response. try_files does not act on any HTTP status codes.

Since you always have /index.php in your filesystem, the @proxy target is never used.

You need to implement the functionality by hooking into WordPress 404 error generation hook and perform the proxying there.

eg flag
Thank you. Since I'm not well versed with Wordpress, I'm trying the luck with nginx. ``location / { try_files $uri $uri/ @proxy; } location @proxy { proxy_pass$1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_intercept_errors on; recursive_error_pages on; error_page 404 = @wordpress; } location @wordpress { rewrite ^/(.*)$ /index.php?$query_string break; }``
us flag
Please don't add configuration snippets to comments, they cannot be read properly.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.