&引用;工人“加工”;在nginx中不允许使用指令

&引用;工人“加工”;在nginx中不允许使用指令,nginx,akka,config,Nginx,Akka,Config,我需要使用这些路由创建nginx.conf文件:/assets-static files,/akka-for hello-world-akka-webapp,/*-默认页面。我的default.conf文件如下所示: worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } ht

我需要使用这些路由创建nginx.conf文件:/assets-static files,/akka-for hello-world-akka-webapp,/*-默认页面。我的default.conf文件如下所示:

worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

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

    upstream hello-akka{
        server localhost:9000;
    }

    server {
        listen 80;

        location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        }

        location /akka {
        proxy_pass http://hello-akka;
        }

        location /assets {
        root /var/www;
        }   
    }
}
每次重新启动nginx服务时,我都会收到以下错误消息:

nginx: [emerg] "worker_processes" directive is not allowed here in /etc/nginx/conf.d/default.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed
我检查了文件本身的结构,我不知道出了什么问题。即使删除这一行,我也会得到相同的“指令不允许”错误,但对于其他行,如pid、事件等。
那么,我该如何修复这样的错误呢?

一个简单的解决方案对我来说很有效

只需在ngnix.conf中添加
server
部分并删除所有内容,如

server {
    listen 80;

    location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    }

    location /akka {
    proxy_pass http://hello-akka;
    }

    location /assets {
    root /var/www;
    }   
}

将该指令放在
/etc/nginx/nginx.conf
的顶部,而不是
/etc/nginx/conf.d/default.conf

worker\u processs
指令仅在配置的顶层有效


现在它默认出现在
/etc/nginx/nginx.conf

中,您的
default.conf
文件显式包含在
/etc/nginx.conf
中。特别是在
http
块中。因此,您在
default.conf
中放置的所有内容都已在
http
上下文中。您应该将
服务器
块以外的所有内容从
default.conf
移动(合并)到
/etc/nginx.conf
,或者从
default.conf
@IvanTsirulev>中删除这些配置行。它解决了我的问题!这解决了问题,但对配置进行了重大更改