【问题标题】:Docker - Permission denied to connect to socket with nginxDocker - 拒绝使用 nginx 连接到套接字的权限
【发布时间】:2017-09-20 15:48:06
【问题描述】:

我正在运行带有 2 个服务的 docker:nginx 和一个用于烧瓶应用程序的 fcgi-socket。 当 nginx 尝试连接到套接字时,它会给出以下内容:

[crit] 7#7: *1 connect() 到 unix:/usr/src/app/flaskapp-fcgi.sock 失败(13:权限被拒绝)

Docker-compose.yml:

version: "3"
services:
    app:
        build: app/
        volumes:
            - app-volume:/usr/src/app

    http_proxy:
        build: nginx/
        ports:
            - '80:80'
            - '443:433'
        depends_on:
            - app
        volumes:
            - app-volume:/usr/src/app
        restart: always

volumes:
  app-volume:

Dockerfile nginx:

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf

Dockerfile 应用程序:

FROM python:3.6.2-onbuild
CMD ["python", "app.fcgi"]

app.fcgi:

#!/usr/bin/env python3

from flup.server.fcgi import WSGIServer
#flask app
from app import app

if __name__ == '__main__':
    WSGIServer(app, bindAddress='./flaskapp-fcgi.sock').run()

nginx.conf:

    ...

    server {
            root /usr/src/app/;

            listen 80 default_server;
            listen [::]:80 default_server;

            location / {
                client_max_body_size 10M;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;

                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param SCRIPT_NAME "";
                fastcgi_pass unix:/usr/src/app/flaskapp-fcgi.sock;
            }

            location /static { try_files $uri =404; }
            location ~ ^/(static|favicon.ico$|robots.txt$) { try_files $uri =404; }

    }

【问题讨论】:

  • 套接字是如何创建的?发布 dockerfiles
  • 尝试将WSGIServer(app, bindAddress='./flaskapp-fcgi.sock').run()更改为WSGIServer(app, bindAddress='./flaskapp-fcgi.sock', umask=0).run()
  • @TarunLalwani 老兄,你救了我的命!一周坚持尝试这么多不同的事情,但解决方案却如此简单......我在 Flask 应用程序上或多或少有相同的设置,这很有效!
  • @Guillaume,感谢分享反馈。 OP 从未分享过反馈,因此我从未将其发布为答案。很高兴知道它有效。现在发布与答案相同

标签: docker nginx flask docker-compose fastcgi


【解决方案1】:

您需要使用umask=0 来完成这项工作

WSGIServer(app, bindAddress='./flaskapp-fcgi.sock', umask=0).run()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    相关资源
    最近更新 更多