这里不允许使用nginx服务器指令


44

我知道这里有很多骗子,但是我似乎无法解决这个问题。

我正在关注有关使用Apache将Nginx设置为反向代理的文章。

我得到这个错误:

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

我的/etc/nginx/nginx.conf样子是这样的:

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;

/etc/nginx/v.hosts/mydomain.com.conf看起来像这样:

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

线索和帮助将不胜感激:)


删除了所有链接,因为它们现在已失效。
斯文

Answers:


39

问题在这里:

    }
include  v.hosts/*.conf;

您已httpinclude指令之前关闭了该块,从而结束了配置。这就是为什么所有包含的文件都不起作用的原因。

要解决此问题,请include使用以下http块中的文件:

    include  v.hosts/*.conf;
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.