Score:0

How to rewrite a file URL in a reverse proxy upstream to a host local path?

vc flag

I setup a Nginx reverse proxy virtual host as below:

location / {
    proxy_pass http://127.0.0.1:8082;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Now, I'd like to add a special file URL in the proxy upstream to a file in the nginx host file system, i.e.

rewrite /rwt-resources/themes/images/676b22ad.png /file/path/under/the/nginx/host.png permanent;

How to make it?

ws flag
What happenned when you tested the change you proposed? How did this not meet your requirement? (I suspect that you don't want a HTTP redirect here, in which case use 'break' or 'last' rather than 'permanent'). And you're heading for a world of pain trying to content management in your webserver / proxy config.
Vincent avatar
vc flag
I test, it failed for being not able to redirect to the nginx host local file path.
Richard Smith avatar
jp flag
So you want one URL to **not** go to `proxy_pass`? Use `location = /rwt-resources/themes/images/676b22ad.png { ... }`
Vincent avatar
vc flag
@RichardSmith Thank you for your tip! I add a location before location /. However, it said 404 in the Developer tools. location /rwt-resources/themes/images/676b22ad.png { internal; alias /root/seb/; } location / { .......
Richard Smith avatar
jp flag
`internal` will respond with 404 if the request is external - you should probably remove it. The alias statement should probably be `alias /file/path/under/the/nginx/host.png;`
Vincent avatar
vc flag
Thank you! However it said 403 error. Even I ran `chown -R www-data:www-data /root/seb`.
I sit in a Tesla and translated this thread with Ai:

mangohost

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.