Nginx 如果端口设为 80 就不行,其他都可以,怎么破 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tanteng
V2EX    NGINX

Nginx 如果端口设为 80 就不行,其他都可以,怎么破

  •  
  •   tanteng
    tanteng 2016-02-06 20:22:00 +08:00 7269 次点击
    这是一个创建于 3617 天前的主题,其中的信息可能已经有所发展或是发生改变。
    server { listen 80 default_server; root "/Users/tanteng/website"; access_log /Applications/MAMP/logs/nginx_access.log; error_log /Applications/MAMP/logs/nginx_error.log debug; location / { index index.html index.php; } 

    上面 listen 改为其他端口就没问题,改成 80 访问就是 502 bad gateway ,看 nginx_error.log,如下 debug :

    2016/02/06 20:21:08 [debug] 5685#0: *4 write new buf t:1 f:0 00000001020022C8, pos 00000001020022C8, size: 156 file: 0, size: 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 http write filter: l:0 f:0 s:156
    2016/02/06 20:21:08 [debug] 5685#0: *4 http output filter "/MAMP/index.php?language=English"
    2016/02/06 20:21:08 [debug] 5685#0: *4 http copy filter: "/MAMP/index.php?language=English"
    2016/02/06 20:21:08 [debug] 5685#0: *4 http postpone filter "/MAMP/index.php?language=English" 0000000102002490
    2016/02/06 20:21:08 [debug] 5685#0: *4 write old buf t:1 f:0 00000001020022C8, pos 00000001020022C8, size: 156 file: 0, size: 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 write new buf t:0 f:0 0000000000000000, pos 00000001001A74C8, size: 120 file: 0, size: 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 write new buf t:0 f:0 0000000000000000, pos 00000001001A63C0, size: 52 file: 0, size: 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 http write filter: l:1 f:0 s:328
    2016/02/06 20:21:08 [debug] 5685#0: *4 http write filter limit 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 writev: 328 of 328
    2016/02/06 20:21:08 [debug] 5685#0: *4 http write filter 0000000000000000
    2016/02/06 20:21:08 [debug] 5685#0: *4 http copy filter: 0 "/MAMP/index.php?language=English"
    2016/02/06 20:21:08 [debug] 5685#0: *4 http finalize request: 0, "/MAMP/index.php?language=English" a:1, c:3
    2016/02/06 20:21:08 [debug] 5685#0: *4 http request count:3 blk:0
    2016/02/06 20:21:08 [debug] 5685#0: *4 http finalize request: -4, "/MAMP/index.php?language=English" a:1, c:2
    2016/02/06 20:21:08 [debug] 5685#0: *4 http request count:2 blk:0
    2016/02/06 20:21:08 [debug] 5685#0: *4 http finalize request: -4, "/MAMP/index.php?language=English" a:1, c:1
    2016/02/06 20:21:08 [debug] 5685#0: *4 set http keepalive handler
    2016/02/06 20:21:08 [debug] 5685#0: *4 http close request
    2016/02/06 20:21:08 [debug] 5685#0: *4 http log handler
    2016/02/06 20:21:08 [debug] 5685#0: *4 free: 0000000102000800, unused: 2
    2016/02/06 20:21:08 [debug] 5685#0: *4 free: 0000000102001800, unused: 603
    2016/02/06 20:21:08 [debug] 5685#0: *4 free: 0000000102000400
    2016/02/06 20:21:08 [debug] 5685#0: *4 hc free: 0000000000000000 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 hc busy: 0000000000000000 0
    2016/02/06 20:21:08 [debug] 5685#0: *4 reusable connection: 1
    2016/02/06 20:21:08 [debug] 5685#0: *4 event timer add: 24: 75000:1454761343364
    2016/02/06 20:21:08 [debug] 5685#0: *4 post event 00000001008374E0
    2016/02/06 20:21:08 [debug] 5685#0: *4 delete posted event 00000001008374E0
    2016/02/06 20:21:08 [debug] 5685#0: *4 http empty handler
    2016/02/06 20:22:23 [debug] 5685#0: *4 event timer del: 24: 1454761343364
    2016/02/06 20:22:23 [debug] 5685#0: *4 http keepalive handler
    2016/02/06 20:22:23 [debug] 5685#0: *4 close http connection: 24
    2016/02/06 20:22:23 [debug] 5685#0: *4 reusable connection: 0
    2016/02/06 20:22:23 [debug] 5685#0: *4 free: 0000000000000000
    2016/02/06 20:22:23 [debug] 5685#0: *4 free: 0000000100700320, unused: 0
    2016/02/06 20:22:23 [debug] 5685#0: *4 free: 0000000100700420, unused: 104

    本机是 MAMP 集成环境,初次配置 nginx ,不太懂,请多指教!谢谢!

    14 条回复    2016-02-07 23:03:48 +08:00
    Starduster
        1
    Starduster  
       2016-02-06 20:49:38 +08:00
    使用别人做的集成环境就不要乱改了。。。删了从 brew 重新装新的 nginx 吧鬼知道那个 MAMP 里有些什么
    Alwaysonline
        2
    Alwaysonline  
       2016-02-06 20:53:22 +08:00 via iPhone
    不太懂,纯猜测, MAMP 会不会是还含 Apache 啊,它占了 80 端口。
    donghouhe
        3
    donghouhe  
       2016-02-06 20:56:07 +08:00
    reusable connection 是不是端口被占用了?
    javaluo
        4
    javaluo  
       2016-02-06 21:04:05 +08:00 via Android
    netstat -an | grep "80"
    kill xxx
    hello2t
        5
    hello2t  
       2016-02-06 21:16:25 +08:00 via iPhone
    很大几率是端口被占用了
    ovear
        6
    ovear  
       2016-02-06 21:28:44 +08:00
    lz 没事开 debug 干嘛。。这段 debug 完全没有问题
    问题在你的 backend 。。看看有没有其他的 host ,或者 include 了其他的文件。。
    一般看到 50x ,请 check 转发, nginx 自身只带了静态文件的 handler
    一般要么是 proxy_pass 炸了 要么是 fcgi_proxy 炸了
    xxsoft
        7
    xxsoft  
       2016-02-06 21:30:13 +08:00 via iPhone
    很简单运营商把 80 端口封了
    wd
        8
    wd  
       2016-02-06 21:30:27 +08:00 via iPhone
    两个可能
    你不是 root
    别的程序占了 80
    tanteng
        9
    tanteng  
    OP
       2016-02-06 21:48:59 +08:00
    @Starduster
    @Alwaysonline MAMP 自带 apache 和 nginx ,可以切换和指定端口,两者切换都没问题, apache 的可以用 80 ,但是 nginx 指定 80 就不行了
    kzzhr
        10
    kzzhr  
       2016-02-06 22:27:34 +08:00 via iPhone
    mac ? 80 需要 sudo
    ericls
        11
    ericls  
       2016-02-07 03:29:09 +08:00
    既然得到了 502 说明 80 端口监听是没问题的啊!

    如果端口占用,根本 nginx 都无法启动

    楼主应该看看错误日志 看看什么问题
    ztrt
        12
    ztrt  
       2016-02-07 11:33:56 +08:00 via Android
    php 问题
    stanhou
        13
    stanhou  
       2016-02-07 16:24:53 +08:00
    你的 NGINX 的 GATEWAY 可能是 APACHE 而不是 PHP-FPM ,把你的 server{}里面的东西都粘出来应该就知道了。如果是 APACHE ,很可能通过 80 端口监听的,自然出现 502 GATEWAY ERROR 。

    题外话,装个虚拟机,用 LINUX 跑服务器吧。 OSX 已经是儿童玩具了,你在上面做 WEB 开发环境,每次 OSX 升级,你都要头疼一次。
    Allianzcortex
        14
    Allianzcortex  
       2016-02-07 23:03:48 +08:00
    netstat ? 不是应该用 lsof -i:50 来查看?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2297 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 02:10 PVG 10:10 LAX 18:10 JFK 21:10
    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