zoukankan      html  css  js  c++  java
  • nginx: [emerg] "upstream" directive is not allowed here in .../.../.../*.conf

    因为临时需要在本机搭建一个nginx服务使用,其实很简单的一个本地server,但是运行的时候就报错:

    192:~ superstar$ nginx
    nginx: [emerg] "upstream" directive is not allowed here in /usr/local/nginx/conf/conf.d/test.com.conf:1
    192:~ superstar$

    检查了我的配置文件 test.com.conf 发现也没有问题:

    upstream a_platform{
                server 127.0.0.1:7100 weight=1 max_fails=2 fail_timeout=5s;
    }
    
    server {
            listen 80;
            server_name a.test.com;
            access_log   /tmp/nginx/a_platform/access.log; 
            error_log    /tmp/nginx/a_platform/error.log; 
    
            location ^~ /{
                proxy_pass http://127.0.0.1:7100/;
            }
            location = /{
                proxy_pass http://127.0.0.1:7100/;
            }
    }

    然后网上查了一下说是“upstream”不能再http这个block里面,于是查看了一下我的nginx.conf的配置;发现果然有问题。

    因为是nginx.conf.default改过来的在进行inlude的时候,是直接在server的block里面的,如下红色部分

    ……………………
    
    events {
        worker_connections  1024;
    }
    
    http {
    # ……………………其他配置文件……………… server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
    include …………/conf/conf.d/*.conf; } # ……………………………………其他配置 }

     而实际上应该在黄色server部分以外,如下所示:

    ……………………
    
    events {
        worker_connections  1024;
    }
    
    
    http {
    #  ……………………其他配置文件………………
        server {
            listen       80;
            server_name  localhost;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
            
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
           include   …………/conf/conf.d/*.conf;
    # ……………………………………其他配置 
    }

    修改完成,运行,问题解决:

    192:~ superstar$ 
    192:~ superstar$ nginx
    192:~ superstar$ ps -ef | grep nginx
      501 28996     1   0 12:50上午 ??         0:00.00 nginx: master process nginx
      501 28997 28996   0 12:50上午 ??         0:00.00 nginx: worker process
    192:~ superstar$

    至此问题解决,也吸取一个教训,有时候越简单地事情越要仔细~

  • 相关阅读:
    算法:合并排序(Merge Sort)
    安全:Web 安全学习笔记
    算法:冒泡排序(Bubble Sort)、插入排序(Insertion Sort)和选择排序(Selection Sort)总结
    算法:四种冒泡排序(Bubble Sort)实现
    算法:阶乘的五种算法
    算法:递归知识文章汇总
    算法:插入排序(Insertion Sort)
    .NET:线程本地存储、调用上下文、逻辑调用上下文
    算法:Rate of Growth
    企业应用:一个够用的、通用的状态机(管理实体的业务状态)
  • 原文地址:https://www.cnblogs.com/haojile/p/12387568.html
Copyright © 2011-2022 走看看