nginx: [emerg] "worker_processes" 指令在 /opt/tools/nginx/conf/nginx.conf:1 中不允许

nginx: [emerg] "worker_processes" directive is not allowed here in /opt/tools/nginx/conf/nginx.conf:1

我不明白为什么会出现此错误。在查看了论坛和许多 nginx 示例之后,我的配置看起来不错。我应该提到我有一个自定义的 nginx 安装。我检查了所有的 nginx 日志文件,但令人惊讶的是它们是空的。

我收到这个错误:

nginx: [emerg] "worker_processes" directive is not allowed here in /opt/tools/nginx/conf/nginx.conf:1

当运行这条命令时:

/opt/tools/nginx/nginx -p /opt/tools/nginx

这是我的 /opt/tools/nginx

的结构
.
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi_params
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── nginx.conf
│   ├── scgi_params
│   ├── uwsgi_params
│   └── win-utf
├── fastcgi_temp
├── html
│   └── favicon.ico
├── logs
│   └── error.log
├── nginx
├── proxy_temp
├── scgi_temp
├── ssl
│   ├── wildcard.tools.abc.com.crt
│   └── wildcard.tools.abc.com.key
└── uwsgi_temp

这是我的配置文件 /opt/tools/nginx/conf/nginx.conf:

worker_processes 2;

daemon off;

error_log /opt/tools/log/nginx/error.log;

pid /opt/tools/nginx/nginx.pid;

events {
    worker_connections  256;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /opt/tools/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    keepalive_timeout  65;

    gzip on;
    gzip_disable "msie6";
    server_tokens off;
    client_max_body_size 50M;


    server {
        listen       443 ssl;
        server_name  controller;

        ssl_certificate      /opt/tools/nginx/ssl/wildcard.tools.abc.com.crt;
        ssl_certificate_key  /opt/tools/nginx/ssl/wildcard.tools.abc.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        ssl_prefer_server_ciphers  on;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }

    }
    include /opt/tools/nginx/conf/*conf;
}

谢谢

nginx.config 中的最后一个命令是 include /opt/tools/nginx/conf/*conf;,它试图第二次加载 /opt/tools/nginx/conf/nginx.conf,但第二次它包含在 http 中堵塞。由于 worker_processes 不能在 http 块中,因此会引发错误。

我会将您的 nginx.conf 提高一级以避免此问题。还需要进行一些其他更改。