Nginx 这样配置,总是报 nginx: [emerg] unknown directive "127.0.0.1:8000"... 是哪里写错了呢? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
miniyao
V2EX    NGINX

Nginx 这样配置,总是报 nginx: [emerg] unknown directive "127.0.0.1:8000"... 是哪里写错了呢?

  •  
  •   miniyao 2018-06-06 14:14:56 +08:00 10303 次点击
    这是一个创建于 2762 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本来的单机配置是这样的,访问正常:

    http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name my-domain.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; client_max_body_size 200M; location / { proxy_pass http://127.0.0.1:8000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; } location /static/ { root /usr/local/nginx/project/; } } } 

    为了增加负载均衡,然后我把上面的单机配置改成:upstream backend {...},测一下就提示错误 nginx: [emerg] unknown directive "127.0.0.1:8000"

    http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream backend { 127.0.0.1:8000; } server { listen 80; server_name my-domain.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; client_max_body_size 200M; location / { proxy_pass http://backend; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; } location /static/ { root /usr/local/nginx/project/; } } } 

    服务器结构是 nginx + gunicorn + flask

    10 条回复    2018-06-06 15:13:47 +08:00
    akira
        1
    akira  
       2018-06-06 14:23:22 +08:00   1
    前面漏了个 server 关键字了吧
    upstream 的语法看一下.
    http://nginx.org/en/docs/http/ngx_http_upstream_module.html
    Zzdex
        2
    Zzdex  
       2018-06-06 14:25:04 +08:00 via iPhone   1
    server 127.0.0.1 试试
    d0m2o08
        3
    d0m2o08  
       2018-06-06 14:28:57 +08:00   1
    强迫症受不了不用 include vhost/*.conf;
    另外楼上说的对 upstream 地址需要用 server 开头
    LeungJZ     4
    LeungJZ  
       2018-06-06 14:33:22 +08:00
    @d0m2o08 #3.
    表示墙裂赞同。
    kslr
        5
    kslr  
       2018-06-06 14:38:11 +08:00 via Android
    如果只有一个配置用什么 include
    miniyao
        6
    miniyao  
    OP
       2018-06-06 14:58:06 +08:00
    @akira
    @Zzdex
    server 关键字是漏打了


    @d0m2o08
    @LeungJZ
    @kslr
    include /usr/local/nginx/conf/*.conf; 加不加没区别呀,我手动执行了一下:
    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    没有用,又报 nginx: [emerg] "worker_processes" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:3
    把 worker_processes 1; 改成 worker_processes auto; 还是同样的错误

    比较奇怪。单机跑的配置很正常,调整了一个 upstream 然后,各种不通
    kslr
        7
    kslr  
       2018-06-06 15:02:37 +08:00   1
    你是不是把 worker_processes 加到 http 里面了
    akira
        8
    akira  
       2018-06-06 15:05:59 +08:00
    @miniyao include /usr/local/nginx/conf/*.conf; 不要随便加,自己搞清楚配置文件是什么结构再加
    miniyao
        9
    miniyao  
    OP
       2018-06-06 15:06:23 +08:00
    @kslr 没,worker processes 是方 http 外面的。
    miniyao
        10
    miniyao  
    OP
       2018-06-06 15:13:47 +08:00
    @akira 谢谢

    光 reload nginx 不管用,reboot 下服务器什么毛病都好了 谢谢大家的建议
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5756 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 02:03 PVG 10:03 LAX 18:03 JFK 21:03
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86