Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I am pretty new to nginx, I host my rails application on nginx+passenger. I want my website to be accessible to only one domain. So I set my nginx conf like the following:

server {
    listen       80;
    root /var/deploy/myapp/current/public;
    passenger_enabled on;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 1y;
        add_header    Cache-Control  public;

I specify the server_name directive, but still, it answers anything which points to this IP and I could see that in the access.log that it answers to other domain names.

Is there anything I am doing wrong?

share|improve this question
up vote 4 down vote accepted

Either make a new virtualhost in addition to the current one in nginx that catches all other domains except the one domain for rails. Or you need to get a dedicated IP-address for your domain.

share|improve this answer
Thanks pkhamre. I have a dedicated ip-address for my domain. The thing is, some other domain name is also pointing to my application(there's some story I also don't know). So you mean I need to create a another block with server_name _; and returns 404 error always? – larryzhao Mar 23 '12 at 7:51
Yes, a server-block with "server_name _;" will do the trick. – pkhamre Mar 23 '12 at 8:00
worked like a charm! – larryzhao Mar 23 '12 at 8:07
Great! I'm glad I could help :) – pkhamre Mar 23 '12 at 11:20

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.