P
P
Pavel2014-10-11 01:01:43
Nginx
Pavel, 2014-10-11 01:01:43

Why doesn't nginx forward to the server when a name is specified in listen?

If I write in hosts on the client and on the server the external ip address of the server with the site address www.example.com (external local), and create an address for nginx

server {
    listen www.example.com:80;
    server_name www.example.com;
    location / {
            proxy_pass http://localhost:8095;
            proxy_set_header    Host            $host;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-for $remote_addr;
            port_in_redirect off;
            proxy_redirect   http://www.example.com/ /;
    }
}

then when I enter www.example.com in the address bar, I will go to my server. If I configure it to an external ip (behind the router), then I can only go to the server when I set listen 80 without explicitly specifying the server name. Why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ingtar, 2014-10-11
@Ingtar

I didn’t understand much, give examples of configs and what you write in the hosts there.
"external local" put me in a dead end :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question