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.

I know there are dupes of this out there, but I can't seem to solve this in my situation.

I'm following this article on setting up nginx as reverse proxy with apache.

And I get this error:

nginx: [emerg] "server" directive is not allowed here in 
       /etc/nginx/v.hosts/mydomain.com.conf:3
nginx: configuration file /etc/nginx/nginx.conf test failed

My /etc/nginx/nginx.conf looks like this:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream; 
    access_log  /var/log/nginx/access.log  main;  
    charset   utf-8;
    keepalive_timeout  65;
    server_tokens       off;
    tcp_nopush          on;
    tcp_nodelay         off;

    server {
          listen 80;
          server_name  _;          
          root   /usr/share/nginx/html;
          index  index.html index.htm;     
       }
    }
include  v.hosts/*.conf;

And this I have /etc/nginx/v.hosts/mydomain.com.conf looks like this:

server {
      listen 80;
      server_name  mydomain.com;

       access_log  off;
       error_log off;

      location / {
        proxy_pass http://127.0.0.1:81;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        Host            $host;
        proxy_redirect          off;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_buffer_size 4k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
      }
 }

Clues and help will be well appreciated :)

Update:

Should I also maybe look at this article. I'm on amazon-ec2, RHEL but this article is about nginx on debian with the sites-enabled config. Should I go with that instead? Will it work?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The problem is here:

    }
include  v.hosts/*.conf;

You have closed the http block before the include directive, thus ending the configuration. This is why none of the included files work.

To fix the issue, include the files within the http block:

    include  v.hosts/*.conf;
}
share|improve this answer
    
Thanks for your reply. Tried this and various other combos. This gives me unexpected "}" in /etc/nginx/nginx.conf:129 nginx: configuration file /etc/nginx/nginx.conf test failed My nginx.conf is filled with all those default comments and what nots. –  gideon Jan 12 '13 at 17:59
    
You need to delete the extra }. –  Michael Hampton Jan 12 '13 at 18:01
    
where is the extra { ? I just moved include into the http { } block, which also has it's own server {} block. If I put the include inside the http block it gives me : unexpected } and removing it gives me a success :S –  gideon Jan 12 '13 at 18:05
    
Should I just bunk this setup and try the one from here => Putting a config in sites-enabled. It's written for debian but I'm on amazon ec2 RHEL. –  gideon Jan 12 '13 at 18:11
1  
But, isn't the ; in the part you pasted? –  Bill Weiss Jan 12 '13 at 20:27

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.