› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
masir
V2EX  ›  NGINX

nginx 修改默认监听端口的问题

  •  
  •   masir · Jun 2, 2018 · 9439 views
    This topic created in 3079 days ago, the information mentioned may be changed or developed.

    对 nginx 配置啥的不太熟悉。这几天在 vps 上搭了 frp,绑定了个域名给 frp 用。但是 frp 配置 vhost 的端口如果不是 80 的话,每次还得在域名后加端口或者再去 nginx 做转发。就想着把 80 端口给 frp 用,然后把 nginx 的默认监听改到 8080 之类的。

    说干就干,先把 nginx 停了之后,把 fprs 配置文件中的 vhost 端口改为 80,然后重启 frp。实现了 frp 的所有 subdomain 能够直接通过类似 test.v2ex.com 直接访问,不用再加端口号。

    然后就开始改 nginx 的配置: /www/server/nginx/conf/nginx.conf 将之前默认监听的 80 端口改为 8080 端口

    server {
        listen 8080;
        listen [::]:8080;
        return 301 https://$host$request_uri;
    }
    

    重新启动 nginx,还是会提示 80 端口已经占用,就是现在没有读到修改后的配置,还是说我改的配置文件不对?

    [root@frps]# nginx 
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] still could not bind()
    

    各位帮忙分析下问题的原因呗....多谢! Ps:nginx 是用宝塔面板直接装的。

    18 replies  •  2018-06-02 23:45:45 +08:00
    chotow
    chotow
    Jun 2, 2018 via Android
    1
    我现在是反过来,nginx 80,然后转发给 frp。想了解你为什么会把 80 让给 frp。
    aricxu
    aricxu
    Jun 2, 2018
    2
    是不是没改全。。,有没有可能有 vhost 也是监听 80 的
    baoshuai33
    baoshuai33
    Jun 2, 2018 via iPhone
    3
    配置文件改错了吧
    NFSwind
    NFSwind
    Jun 2, 2018
    4
    nginx.conf 和 conf.d 目录下的都看看,有时候还有 site-*之类的配置文件也需要看看
    aihttp
    aihttp
    Jun 2, 2018
    5
    宝塔面板搭建的 Nginx 有主机区分,所以你应该修改具体 Vhost 的配置文件,而不是 nginx.conf
    masir
    masir
    OP
    Jun 2, 2018 via Android
    6
    @chinanala 谢谢,我再去宝塔看看
    masir
    masir
    OP
    Jun 2, 2018 via Android
    7
    @chotow 😂😂
    masir
    masir
    OP
    Jun 2, 2018 via Android
    8
    @baoshuai33 估计是还有什么地方没改
    baoshuai33
    baoshuai33
    Jun 2, 2018 via iPhone
    9
    @masir 配置文件自己搜 80,
    liuxu
    liuxu
    Jun 2, 2018
    10
    看看又没有 include 其他配置文件,里面有没有占用
    twor
    twor
    Jun 2, 2018
    11
    listen [::]:8080;
    删掉试试
    huaxianyan
    huaxianyan
    Jun 2, 2018 via Android
    12
    我是用反代到指定端口
    ryd994
    ryd994
    Jun 2, 2018 via Android
    13
    赌 5 毛,/etc/nginx/nginx.conf
    billchenchina
    billchenchina
    Jun 2, 2018
    14
    nginx -s reload

    重新加载配置文件?
    loveminds
    loveminds
    Jun 2, 2018
    15
    @ryd994 只有 apt 和 yum 装的 nginx 才在 etc,第三方的一般都是 /usr/local/nginx 之类的
    masir
    masir
    OP
    Jun 2, 2018
    16
    @twor 试了不行~
    SakuraKuma
    SakuraKuma
    Jun 2, 2018
    18
    grep -rn '80' /path/to/nginx/conf
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2395 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 11:14 · PVG 19:14 · LAX 03:14 · JFK 06:14
    ♥ Do have faith in what you're doing.