admin管理员组

文章数量:1389749

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
  • To not repeat myself, generally you should set up the backend app, you cannot solve such tasks using nginx alone. From a quick Google search, it seems that WireMock doesn't have such a setting. Some (admittedly ugly) workarounds can be found in the comment under the answer I referenced above, and the sub_filter approach suggested in the answer to your question is definitely one of them. – Ivan Shatsky Commented Mar 14 at 13:51
  • Thanks @IvanShatsky, I tried some ugly workarounds to achieve the outcome what I needed, but nothing worked. The sub_filter was working to an extent but didn't solve completely. Since my app was running in an ECS container/ALB, I made changes in the ALB to reach the __admin endpoint which eventually resolved my problem. – Rohit12 Commented Mar 22 at 14:04
Add a comment  | 

1 Answer 1

Reset to default -1

Are 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.

本文标签: Nginx reverse proxy setup for redirectsStack Overflow