【问题标题】:Nginx permission deniedNginx 权限被拒绝
【发布时间】:2015-10-09 17:55:26
【问题描述】:

我想在使用 centOS 7 的服务器上部署我的烧瓶服务。所以我按照本教程进行操作 - https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7

运行systemctl start nginx 命令后,我得到了这个错误:

nginx: [emerg] bind() to 0.0.0.0:5000 failed (13: Permission denied)

我的nginx.conf 文件:

server {
    listen 5000;
        server_name _;
        location / {
                include uwsgi_params;
                uwsgi_pass unix:/root/fiproxy/fiproxyproject/fiproxy.sock;
        }
    }

注意: 烧瓶服务和 wsgi 工作正常。我尝试使用超级用户运行 nginx,但错误仍然存​​在。

【问题讨论】:

  • 你用 root 用户运行 systemctl 命令?因为这是我能想到的权限被拒绝错误的唯一原因

标签: nginx flask


【解决方案1】:

在网上搜索了很多之后,我找到了解决问题的方法。

我运行了这个命令来获取我机器中所有使用的端口:semanage port -l。 之后,我过滤了输出:semanage port -l | grep 5000

我发现这个5000端口被commplex_main_port_t使用了,我在speedguide中搜索发现:5000 tcp,udp **UPnP**

结论,也许我的问题是绑定一个标准端口。

要添加所需的端口,请使用以下命令:

sudo semanage port -a -t http_port_t  -p tcp [yourport]

现在用 sudo 运行 nginx:

sudo systemctl stop nginx
sudo systemctl start nginx

【讨论】:

  • 运行 semanage 命令 ValueError: Port tcp/3306 already defined 后出现此错误
  • 你应该将 -a 更改为 -m 以在我的情况下进行修改。
【解决方案2】:

Nginx 主进程需要root权限。因为它需要绑定端口。
您需要在 root 用户下启动 Nginx。
然后你可以在nginx.conf中定义子进程的用户。

【讨论】:

  • 我正在使用 Root 运行主进程。我用root配置了所有,问题仍然存在。
  • fiproxy.sock的权限是什么
  • 我创建了一个nginx用户。
猜你喜欢
  • 2020-08-25
  • 2021-03-27
  • 2017-11-03
  • 2020-02-08
  • 2018-10-02
  • 1970-01-01
  • 2016-04-21
  • 2018-07-15
  • 2015-12-21
相关资源
最近更新 更多