Score:0

Images get a 404 error when using Nginx's reverse proxy

nl flag

I'm using Nginx's reverse proxy to route blog.example.com to example.com/blog/.

Most things work fine, but when I click on an image in example.com/blog, I get a 404 error.

I know that this is caused by the actual image not being in /blog/wp-content/uploads/, so I tried applying some rewrite rules, but they don't work.

Can someone give me some advice on how to solve this problem?

location /blog/ {
    rewrite ^([^\?#]*/)([^\?#\./]+)([\?#].*)?$ $1$2/$3 permanent;
    add_header 'Access-Control-Allow-Origin' * always;
    proxy_ssl_server_name on;

    proxy_pass https://blog.example.com/;
    proxy_read_timeout 300;
    proxy_send_timeout 300;
    send_timeout 300;
    proxy_connect_timeout 300;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host en.vietnamguide.co.kr;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Connection "";
    
}

location ~ ^/blog/wp-content/uploads/(.*) { 
    if (!-f $request_filename) { 
        rewrite ^/blog/wp-content/uploads/(.*)$ https://blog.example.com/wp-content/uploads/$1 redirect; 
    } 
}
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.