How to set up a reverse proxy server for changing the link (not only the domain) to different services?

using machine translation, sorry for my English

What I’m trying to do: The purpose of setting up a reverse proxy server is to change the final link of a particular corporate service to my link.

Lets assume there are 4 services with the following links for the end user:

1cloud[dot]com/kjbehr
2cloud[dot]com/sjhdbu
service[dot]com/fhtfvhh
app.service[dot]com/khfdvho

Real links can be longer, with subdomains and, most importantly, not easy to remember.
For internal purposes we should use our own domain mydomain[dot]com.

1cloud[dot]com/kjbehr/* β†’ mydomain[dot]com/1cloud/*
2cloud[dot]com/sjhdbu/* β†’ mydomain[dot]com/2cloud/*
service[dot]com/fhtfvhh/* β†’ mydomain[dot]com/service/*
app.service[dot]com/khfdvho/* β†’ mydomain[dot]com/dir/appservice/*

Where I’m stuck: On nginx, according to the manual it doesn’t quite work, in fact, only the domain is successfully substituted, but the path is not.

1cloud[dot]com/kjbehr/* β†’ mydomain[dot]com/1cloud/* β†’ mydomain[dot]com/kjbehr/*
2cloud[dot]com/sjhdbu/* β†’ mydomain[dot]com/2cloud/* β†’ mydomain[dot]com/sjhdbu/*
service[dot]com/fhtfvhh/* β†’ mydomain[dot]com/service/* β†’ mydomain[dot]com/fhtfvhh/*
app.service[dot]com/khfdvho/* β†’ mydomain[dot]com/dir/appservice/* β†’ mydomain[dot]com/khfdvho/*

Is there a solution to this problem?

1 Like

One thing that would help greatly here is to include your sanitized NGINX config(s). This will help with context and give a better picture of how NGINX will process incoming requests.

The nginx.conf can be found in /etc/nginx in most cases.

I am also including a blog post, I think may help, if I am understanding your use case correctly.

Creating NGINX Rewrite Rules

This is my config

server {

    server_name mydomain.com;
    access_log /var/log/nginx/mydomain-access.log;
    error_log /var/log/nginx/mydomain-error.log;
#    return 301 https://$server_name$request_uri;
#    proxy_read_timeout 600;


}

server {
    listen 443 ssl;
    server_name mydomain.com;
    access_log /var/log/nginx/mydomain-ssl-access.log;
    error_log /var/log/nginx/mydomain-ssl-error.log;

    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    location /.well-known/acme-challenge/ {
        root /var/www/acme;
    }
    location /service/ {
        proxy_pass https://service.com/fhtfvhh/;
	proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-Proto https;
    }
    location /fhtfvhh/ {
        proxy_pass https://service.com/fhtfvhh/;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
    }
}```