nginx: [emerg] "upstream" directive is not allowed

时间:2025-03-18 20:57:17

配置完nginx,在启动的时候遇到如下问题:
nginx: [emerg] "upstream" directive is not allowed here in /usr/local/nginx/conf/:7

配置,如下:
upstream con {
    server 127.0.0.1:8080;
}


解决办法:

upstream backend 位置放错了, upstream位置应该放在http模块里面 但必须是在server模块的外面


http
{
    include ;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    ..................................................

    upstream con {
    server 127.0.0.1:8080;
}

}
对此段代码放入httpd模块中,重启服务可完成问题的解决。