Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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;
}
share|improve this answer

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

share|improve this answer
    
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 7 at 8:13
    
No, no, it is an answer - it's just completely wrong, I think, and not very detailed besides. –  Falcon Momot Mar 7 at 10:18
1  
@syneticon-dj This actually is an answer to the question. It just happens to be wrong. –  Michael Hampton Mar 7 at 10:18
    
It is not wrong. It is correct and it works. –  Mitar Dec 16 at 16:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.