此处不允许使用 nginx 服务器指令

gid*_*eon 50 configuration nginx

我知道那里有骗子,但在我的情况下我似乎无法解决这个问题。

我正在关注一篇关于使用 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
Run Code Online (Sandbox Code Playgroud)

我的/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;
Run Code Online (Sandbox Code Playgroud)

/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;
      }
 }
Run Code Online (Sandbox Code Playgroud)

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

Mic*_*ton 43

问题在这里:

    }
include  v.hosts/*.conf;
Run Code Online (Sandbox Code Playgroud)

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

要解决此问题,块中include的文件http

    include  v.hosts/*.conf;
}
Run Code Online (Sandbox Code Playgroud)