V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
masir
V2EX  ›  NGINX

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

  •  
  •   masir · 2018-06-02 12:26:47 +08:00 · 7664 次点击
    这是一个创建于 2126 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    重新加载配置文件?
    loveminds
        15
    loveminds  
       2018-06-02 18:13:53 +08:00
    @ryd994 只有 apt 和 yum 装的 nginx 才在 etc,第三方的一般都是 /usr/local/nginx 之类的
    masir
        16
    masir  
    OP
       2018-06-02 20:10:45 +08:00
    @twor 试了不行~
    SakuraKuma
        18
    SakuraKuma  
       2018-06-02 23:45:45 +08:00
    grep -rn '80' /path/to/nginx/conf
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1467 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:23 · PVG 01:23 · LAX 10:23 · JFK 13:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.