V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
tanteng
V2EX  ›  NGINX

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

  •  
  •   tanteng ·
    tanteng · Feb 6, 2016 · 7420 views
    This topic created in 3735 days ago, the information mentioned may be changed or developed.
    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 replies    2016-02-07 23:03:48 +08:00
    Starduster
        1
    Starduster  
       Feb 6, 2016
    使用别人做的集成环境就不要乱改了。。。删了从 brew 重新装新的 nginx 吧鬼知道那个 MAMP 里有些什么
    Alwaysonline
        2
    Alwaysonline  
       Feb 6, 2016 via iPhone
    不太懂,纯猜测, MAMP 会不会是还含 Apache 啊,它占了 80 端口。
    donghouhe
        3
    donghouhe  
       Feb 6, 2016
    reusable connection 是不是端口被占用了?
    javaluo
        4
    javaluo  
       Feb 6, 2016 via Android
    netstat -an | grep "80"
    kill xxx
    hello2t
        5
    hello2t  
       Feb 6, 2016 via iPhone
    很大几率是端口被占用了
    ovear
        6
    ovear  
       Feb 6, 2016
    lz 没事开 debug 干嘛。。这段 debug 完全没有问题
    问题在你的 backend 。。看看有没有其他的 host ,或者 include 了其他的文件。。
    一般看到 50x ,请 check 转发, nginx 自身只带了静态文件的 handler
    一般要么是 proxy_pass 炸了 要么是 fcgi_proxy 炸了
    xxsoft
        7
    xxsoft  
       Feb 6, 2016 via iPhone
    很简单运营商把 80 端口封了
    wd
        8
    wd  
       Feb 6, 2016 via iPhone
    两个可能
    你不是 root
    别的程序占了 80
    tanteng
        9
    tanteng  
    OP
       Feb 6, 2016
    @Starduster
    @Alwaysonline MAMP 自带 apache 和 nginx ,可以切换和指定端口,两者切换都没问题, apache 的可以用 80 ,但是 nginx 指定 80 就不行了
    kzzhr
        10
    kzzhr  
       Feb 6, 2016 via iPhone
    mac ? 80 需要 sudo
    ericls
        11
    ericls  
       Feb 7, 2016
    既然得到了 502 说明 80 端口监听是没问题的啊!

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

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

    题外话,装个虚拟机,用 LINUX 跑服务器吧。 OSX 已经是儿童玩具了,你在上面做 WEB 开发环境,每次 OSX 升级,你都要头疼一次。
    Allianzcortex
        14
    Allianzcortex  
       Feb 7, 2016
    netstat ? 不是应该用 lsof -i:50 来查看?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5085 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 76ms · UTC 08:21 · PVG 16:21 · LAX 01:21 · JFK 04:21
    ♥ Do have faith in what you're doing.