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

时间:2018-03-24 22:31:34

标签: nginx centos6.5 worker-processes

我无法弄清楚为什么我会收到此错误。在查看论坛和许多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;
}

感谢

1 个答案:

答案 0 :(得分:1)

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

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