• 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$

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

  • 相关阅读:
    PHP7.X 安装mysql扩展
    雷军说云计算是下一个风口
    玩转超级列表框4 拖放组建的使用。
    玩转超级列表框第三课的自编代码
    易语言核心支持库 文本操作与文件读写
    插入表项的标题和置标题的标题的区别
    精易模块8.2 类_超级列表框 外部超级列表框的区别和使用注意点
    如何理解动态规划
    雷军:互联网思维本质上就是群众路线
    纯互联网项目“失宠”乐博资本杨宁称今后只投O2O
  • 原文地址:https://www.cnblogs.com/haojile/p/12387568.html
Copyright © 2020-2023  润新知