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$

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

  • 相关阅读:
    Spring框架之环绕增强
    Spring框架之最终增强
    Spring框架使用注解实现IOC的配置
    [算法] 带有条件的全排列 [dfs + set]
    [算法] 字符串的全排列 [dfs 递归神技]
    [面试] 十七道海量数据处理面试题与Bitmap详解 [未细看]
    [算法] 输出 字符串的全部子组合 [dfs 递归神技]
    [linux] 进程间通讯的几种方式
    [面试] 在数组查找这样的数,它大于等于左侧所有数,小于等于右侧所有数
    [算法] 彻头彻尾理解二分检索 6 种变换
  • 原文地址:https://www.cnblogs.com/haojile/p/12387568.html
Copyright © 2011-2022 走看看