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

2018-06-02 12:26:47 +08:00
 masir

对 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 是用宝塔面板直接装的。

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

重新加载配置文件?
loveminds
2018-06-02 18:13:53 +08:00
@ryd994 只有 apt 和 yum 装的 nginx 才在 etc,第三方的一般都是 /usr/local/nginx 之类的
masir
2018-06-02 20:10:45 +08:00
@twor 试了不行~
twor
2018-06-02 22:11:33 +08:00
SakuraKuma
2018-06-02 23:45:45 +08:00
grep -rn '80' /path/to/nginx/conf

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/459786

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX