Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Log says:

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

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

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:


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

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;
location / {
    proxy_pass http://localhost:8080;
share|improve this answer

you can use dnsmasq on for resolving from /etc/hosts and place resolver 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 '14 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 '14 at 10:18
@syneticon-dj This actually is an answer to the question. It just happens to be wrong. – Michael Hampton Mar 7 '14 at 10:18
It is not wrong. It is correct and it works. – Mitar Dec 16 '14 at 16:50

Your Answer


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.