0

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; 
    } 
}
Seomari
  • 21
  • 2

0 Answers0