Nginx upstream绑定端口失败nginx: [emerg] bind() to 0.0.0.0:6445 failed (13: Permission denied)

今天在nginx配置upstream代理(四层负载均衡)重启nginx发现绑定端口失败

报错:提示端口绑定失败,权限不足

尝试将user模块改成root用户,重启nginx还是不行,并修改nginx相关目录权限为666,还是以前的报错。

[root@k8s-master2 nginx]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@k8s-master2 nginx]# journalctl -u nginx

Dec 13 14:59:57 k8s-master2 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 13 14:59:57 k8s-master2 nginx[10664]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 13 14:59:57 k8s-master2 nginx[10664]: nginx: [emerg] bind() to 0.0.0.0:16443 failed (13: Permission denied)
Dec 13 14:59:57 k8s-master2 nginx[10664]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 13 14:59:57 k8s-master2 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 13 14:59:57 k8s-master2 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 13 14:59:57 k8s-master2 systemd[1]: Unit nginx.service entered failed state.
Dec 13 14:59:57 k8s-master2 systemd[1]: nginx.service failed.
Dec 13 15:02:31 k8s-master2 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 13 15:02:31 k8s-master2 nginx[10724]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 13 15:02:31 k8s-master2 nginx[10724]: nginx: [emerg] bind() to 0.0.0.0:6445 failed (13: Permission denied)
Dec 13 15:02:31 k8s-master2 nginx[10724]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 13 15:02:31 k8s-master2 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 13 15:02:31 k8s-master2 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 13 15:02:31 k8s-master2 systemd[1]: Unit nginx.service entered failed state.
Dec 13 15:02:31 k8s-master2 systemd[1]: nginx.service failed.

查看配置Nginx文件

[root@k8s-master2 nginx]# cat /etc/nginx/nginx.conf
user nginx; 
worker_processes auto;  
error_log /var/log/nginx/error.log;  
pid /run/nginx.pid;  
  
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.  
include /usr/share/nginx/modules/*.conf;  
  
events {  
    worker_connections 1024;  
}  
stream {  
        log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';  
        access_log /var/log/nginx/k8s-access.log main;  
  
        upstream k8s-apiserver {  
                server 192.168.100.148:6443;  
                server 192.168.100.149:6443;  
                # Add more servers here if needed  
        }  
        server {  
                listen 6445; 
                proxy_pass k8s-apiserver;  
                # Add health check here if needed  
        }  
}

配置文件无误,检查系统其他配置

发现selinux没有关闭,关闭selinux,并重启nginx,nginx运行正常!

[root@k8s-master2 nginx]# setenforce 0
[root@k8s-master2 nginx]# sed -i 's/^SELINUX=permissive/SELINUX=disabled/' /etc/selinux/config
[root@k8s-master2 nginx]# systemctl restart nginx

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据引用内容和,当nginx启动时报错"bind() to 0.0.0.0:XXXX failed (13: Permission denied)"时,这表示该端口被拒绝访问。 这个错误提示中的"13: Permission denied"意味着没有权限访问该端口。这种错误通常有两种情况: 1. 端口小于1024的情况:在Linux系统中,只有root用户才有权限访问端口号小于1024的端口。因此,如果你使用非root用户启动nginx,并尝试绑定一个小于1024的端口,就会出现这个错误。 2. 端口大于1024的情况:在这种情况下,虽然不需要root权限,但是系统可能会阻止某些非特权用户访问该端口,导致拒绝访问的错误。 为了解决这个问题,有以下几种方法: - 如果你希望使用小于1024的端口,可以使用root用户启动nginx。然后通过指定user指令来将权限切换到非root用户,以增加安全性。 - 如果你希望使用大于1024的端口,可以确保当前用户对该端口具有足够的权限。你可以检查该端口是否被其他进程占用,或者尝试使用其他端口。 - 可以使用sudo命令来以root权限启动nginx,然后通过配置文件指定非root用户进行运行。 - 可以通过修改操作系统的安全策略,允许非特权用户访问指定的端口。 综上所述,当出现nginx报错"bind() to 0.0.0.0:XXXX failed (13: Permission denied)"时,你需要确保对应的端口号有足够的权限访问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied)](https://blog.csdn.net/hwx865/article/details/130845239)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值