I have an website running in https://localhost:7443/__admin. I have nginx running in the same host in https://localhost:8443.
I want the users to launch the webapp with the url https://localhost:8443/wiremock so that it redirects to https://localhost:7443/__admin. I used the below nginx conf to redirect. When I launch the app in chrome, the first call to the webapp is successful but the subsequent calls are returning 404. The subsequent calls are not requested by the user, its internally made based on the webapp.
When I looked at the chrome console, what I noticed is the subsequent calls(the referred calls) are redirected to https://localhost:8443/__admin instead of https://localhost:8443/wiremock/__admin. Appreciate if someone can help what is missing in my config.
server {
listen 8443 ssl;
server_name localhost;
access_log /dev/stdout;
error_log /dev/stderr;
ssl_certificate /etc/ssl/certs/self-signed-cert-for-instance.crt;
ssl_certificate_key /etc/ssl/private/self-signed-cert-for-instance.key;
location /wiremock/__admin {
rewrite ^/wiremock(.*)$ $1 break;
proxy_pass https://localhost:7443/__admin;
proxy_set_header Host $host;
}
}
I have an website running in https://localhost:7443/__admin. I have nginx running in the same host in https://localhost:8443.
I want the users to launch the webapp with the url https://localhost:8443/wiremock so that it redirects to https://localhost:7443/__admin. I used the below nginx conf to redirect. When I launch the app in chrome, the first call to the webapp is successful but the subsequent calls are returning 404. The subsequent calls are not requested by the user, its internally made based on the webapp.
When I looked at the chrome console, what I noticed is the subsequent calls(the referred calls) are redirected to https://localhost:8443/__admin instead of https://localhost:8443/wiremock/__admin. Appreciate if someone can help what is missing in my config.
server {
listen 8443 ssl;
server_name localhost;
access_log /dev/stdout;
error_log /dev/stderr;
ssl_certificate /etc/ssl/certs/self-signed-cert-for-instance.crt;
ssl_certificate_key /etc/ssl/private/self-signed-cert-for-instance.key;
location /wiremock/__admin {
rewrite ^/wiremock(.*)$ $1 break;
proxy_pass https://localhost:7443/__admin;
proxy_set_header Host $host;
}
}
Share Improve this question asked Mar 13 at 6:43 Rohit12Rohit12 531 silver badge6 bronze badges 2 |1 Answer
Reset to default -1Are you requesting subsequent resource loading in the backend?
If so, try specifying sub_filter
example
location /wiremock/__admin {
rewrite ^/wiremock(.*)$ $1 break;
proxy_pass https://localhost:7443/__admin;
proxy_set_header Host $host;
sub_filter '/__admin' '/wiremock/__admin';
sub_filter_once off;
proxy_set_header Accept-Encoding "";
}
sub_filter
will replace all response bodies from the backend, so be careful not to make unintended matches.
http://nginx./en/docs/http/ngx_http_sub_module.html
I think the best way to fix it is to specify resource loading that matches the front.
sub_filter
approach suggested in the answer to your question is definitely one of them. – Ivan Shatsky Commented Mar 14 at 13:51