大网数据广告活动
服务器运维问答

nginx server directive is not allowed here

· 52CE 我爱测

I know there are dupes of this out there, but I can't seem to solve this in my situation. I'm following an article on setting up nginx as reverse proxy with apache. And I get this error: nginx: [emerg] "server" directive is not a…

问题原文

原帖链接 · gideon · CC BY-SA 3.0

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

I'm following an 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 :)

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

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;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-01-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。