Website A nginx reverse proxy website B. The problem is that the static address access path of website B is /static/style/
This will cause static file access to become A website domain name/static/style/ actually belongs to B website, so 404 appears
I use /gongju/ as the reverse proxy to identify
A website nginx reverse proxy is modified as follows
location ^~ /gongju/ { proxy_pass http://Website B/; proxy_set_header Host $host; 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; # Fix redirect paths proxy_redirect ~^/(.*)$ /gongju/$1; sub_filter_once off; sub_filter_types *; # 1. HTML/JS/CSS Common Path Formats sub_filter '="/' '="/gongju/'; sub_filter "='/" "='/gongju/"; sub_filter 'url(/' 'url(/gongju/'; sub_filter 'url("/' 'url("/gongju/'; sub_filter "url('/" "url('/gongju/"; sub_filter 'src="/' 'src="/gongju/'; sub_filter "src='/" "src='/gongju/"; sub_filter 'href="/' 'href=" rel="external nofollow" /gongju/'; sub_filter "href='/" "href='/gongju/"; sub_filter 'action="/' 'action="/gongju/'; sub_filter "action='/" "action='/gongju/"; # 2. Strings that splice paths in JS sub_filter '"/api' '"/gongju/api'; sub_filter "'/api" "'/gongju/api"; sub_filter '"/static' '"/gongju/static'; sub_filter "'/static" "'/gongju/static"; # 3. Hard-coded link in the backend return sub_filter 'http://B website' '$scheme://$host/gongju';}
This is the article about handling static file 404 exceptions in Nginx reverse proxy. For more related contents of static file 404 in Nginx reverse proxy, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!