A
A
Alexander2020-11-13 12:07:06
Nginx
Alexander, 2020-11-13 12:07:06

How to make nginx prox for a service on another domain?

There is a main site, let's call it https://example.com
It has a service at /public-service/ There is

also another domain, let's call it https://public-service.com
How can I make sure that ALL requests to this additional domain was proxied to the main domain with the address /public-service/ ?

https://public-service.com -> https://example.com/public-service/
https://public-service.com/second-url -> https://example.com/public-service/
https://public-service.com/another-url -> https://example.com/public-service/

I'm making a proxy but it's proxying the whole site

server {
    listen 80;
       server_name public-service.com;
        location / {
                access_log off;
                proxy_pass https://example.com/public-service;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect default;
        }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-11-13
@alexmixaylov

rewrite ^ /public-service/ break;
proxy_pass https://example.com;

proxy_set_header Host $host;

This line is redundant.
In the question httpS://public-service.com, so what is needed is not listen 80;, but listen 443 ssl;.
Well, add a certificate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question