关于nginx:Nginx非root用户不能绑定端口

问题形容

在AWS上以普通用户身份装置nginx,启动时呈现无奈绑定8201端口的问题

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 一 2021-04-19 12:28:16 CST; 9s ago
     Docs: http://nginx.org/en/docs/
  Process: 14781 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

4月 19 12:28:16 ip-172-31-6-83 systemd[1]: Starting nginx - high performance web server...
4月 19 12:28:16 ip-172-31-6-83 nginx[14781]: nginx: [emerg] bind() to 0.0.0.0:8201 failed (1...ed)
4月 19 12:28:16 ip-172-31-6-83 systemd[1]: nginx.service: control process exited, code=exite...s=1
4月 19 12:28:16 ip-172-31-6-83 systemd[1]: Failed to start nginx - high performance web server.
4月 19 12:28:16 ip-172-31-6-83 systemd[1]: Unit nginx.service entered failed state.
4月 19 12:28:16 ip-172-31-6-83 systemd[1]: nginx.service failed.

问题解决

在网上搜寻到相干信息,都是提醒非用户不能操作1024以上的端口,跟以后问题不符,起初在博客园上找到解决方案,是跟setlinux无关。

[ec2-user@ip-172-31-6-83 nginx]$ sudo getenforce # 查看setlinux状态
Enforcing
[ec2-user@ip-172-31-6-83 nginx]$ sudo setenforce 0
[ec2-user@ip-172-31-6-83 nginx]$ sudo getenforce
Permissive
[ec2-user@ip-172-31-6-83 nginx]$ sudo systemctl start nginx
[ec2-user@ip-172-31-6-83 nginx]$ ss -tunlp | grep 8201
tcp    LISTEN     0      128       *:8201                  *:*

如果须要永恒敞开selinux,请编辑/etc/selinux/config文件,将SELINUX=disabled。之后将零碎重启一下即可。

vim /etc/selinux/config

原文链接

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据