3

Having nginx installed and Apache on port 8080. The trouble is: I'm building site for production domain (let's say mysite.com) and have everything configured for that domain. I change my Windows hosts file to redirect mysite.com to server's IP and it worked well... before I installed nginx. Nginx resolves domains itself and (obviously) can't resolve the domain mysite.com

Log says:

2012/02/07 07:35:29 [error] 11758#0: *1 mysite.com could not be resolved (110: Operation timed out), client: 89.112.11.xx, server: myssite.com, request: "GET / HTTP/1.1", host: "mysite.com"

Well, then I try to change hosts file on my server. I do this thing in the /etc/hosts:

127.0.0.1 mysite.com

Okay, let's try! If this took effect, at least wget should find it correct, right? As far as I have Apache on the 8080th port, i can wget the main page:

wget mysite.com

It downloads the correct page. This means that /etc/hosts does well.

But ngnix still does not resolve it! Even after I restarted the server. Why? Does it have its own resolver or what? How to make it work?

Dmitry
  • 169
  • 3
  • 5

2 Answers2

5

you can use dnsmasq on 127.0.0.1 for resolving from /etc/hosts and place resolver 127.0.0.1 to nginx config

Vasily
  • 69
  • 1
  • 1
  • Vasily, welcome to ServerFault. If you have additions to an already posted answer or clarification requests to a specific question, please consider posting a comment instead of an answer. The "answer" functionality is reserved for ... well, answers exclusively. – the-wabbit Mar 07 '14 at 08:13
  • No, no, it *is* an answer - it's just completely wrong, I think, and not very detailed besides. – Falcon Momot Mar 07 '14 at 10:18
  • 1
    @syneticon-dj This actually _is_ an answer to the question. It just happens to be wrong. – Michael Hampton Mar 07 '14 at 10:18
  • It is not wrong. It is correct and it works. – Mitar Dec 16 '14 at 16:50
4

nginx doesn't use hosts file for domain resolving. If you use domain names for listen, proxy_pass or fastcgi_pass, you can use IP address or localhost instead:

listen localhost:80;
server_name mysite.com;
...
location / {
    proxy_pass http://localhost:8080;
}
Vanav
  • 186
  • 4