D
D
Denis Goncharenko2021-12-29 12:46:39
Nginx
Denis Goncharenko, 2021-12-29 12:46:39

How to proxy to the same domain in Nginx?

Is it possible to proxy to a domain that matches the server name?

server {
        listen          80;
        server_name     domain.com;

        location / {
                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_pass http://domain.com;
        }
}


Here, as I understand it, there is some kind of looping, as it tries to proxy to the same server. Is it possible to somehow make the proxy_pass command perceive domain.com not as a local server, but access the domain.com domain via DNS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2021-12-29
@shambler81

127.0.0.1 - for this, it’s perfect what you come up with
if it’s on another server, then by IP,
because config substitution goes via http reffer

Z
zvl, 2022-01-07
@zvl

There is nothing to answer for a person who is too lazy to read the official documentation in Russian - https://nginx.org/ru/docs/beginners_guide.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question