繁体   English   中英

在Mac中connect()到unix:///tmp/web2py.socket失败(13:权限被拒绝)

[英]connect() to unix:///tmp/web2py.socket failed (13: Permission denied) in mac

我已经按照下面的教程设置了nginx + web2py + uwsgi,但是nginx无法访问uwsgi套接字。 下面是我的配置文件。 当我打开localhost时,它显示502错误的网关,并且nginx错误日志显示了尝试访问web2py.socket时被拒绝的权限

在ubuntu上设置web2py + uwsgi + nginx

/usr/local/etc/nginx/nginx.conf中的nginx conf文件

#user  nobody;
worker_processes  1;

error_log  /var/log/nginx/nginx_error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen          80;
        server_name     $hostname;
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /Users/sudhakar/Desktop/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###



        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;

            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section

            ### remove the comments if you use uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
    }



    server {
        listen 443 default_server ssl;
        server_name     $hostname;
        ssl_certificate         /usr/local/etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /usr/local/etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        keepalive_timeout    70;
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section
            ### remove the comments if you want to enable uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /Users/sudhakar/Desktop/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###

}
    include servers/*;
}

/etc/uwsgi/web2py.ini中的uwsgi conf文件

[uwsgi]
socket = /tmp/web2py.socket
chmod-socket = 600
uid = _www
gid = _www
pythonpath = /Users/sudhakar/Desktop/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
touch-reload = /Users/sudhakar/Desktop/web2py/routes.py
cron = 0 0 -1 -1 -1 python /Users/sudhakar/Desktop/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true

下面的命令用于运行uwsgi

exec /usr/local/bin/uwsgi --ini /etc/uwsgi/web2py.ini

您需要以同一用户运行nginxuwsgi进程。 或者,您可以更改套接字文件权限,但是由于安全问题,不建议您更改它。

解决方案1:

更改#user nobody; user _www; /usr/local/etc/nginx/nginx.conf文件中(以_www用户身份运行Nginx进程)

然后重启nginx服务

解决方案2:

/etc/uwsgi/web2py.ini文件中,将chmod-socket = 600行更改为chmod-socket = 666 (不建议)

然后重新启动uwsgi服务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM