You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下Nginx部署Django遇权限拒绝错误求助

Fixing "Permission Denied" for Unix Socket in Nginx + Django on Ubuntu 16.04

Hey there, I’ve dealt with this exact permission issue when deploying Django with Nginx on Ubuntu before—let’s get your site up and running smoothly.

Why This Happens

The error connect() to unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock failed (13: Permission denied) means the Nginx process (which runs as the www-data user by default) doesn’t have access to your uWSGI socket file. That socket was probably created under your user account (teddycrepineau), and by default, www-data can’t read or write to files owned by another user’s private group.

Step-by-Step Fixes

  • Check the socket’s current permissions
    First, confirm who owns the socket and what access it allows:

    ls -l /home/teddycrepineau/contoursandcolors/contoursandcolors.sock
    

    You’ll almost certainly see it’s owned by teddycrepineau:teddycrepineau, with tight permissions like 600 (only the owner can interact with it).

  • Add Nginx’s user to your group
    Give www-data access to files in your user group by adding it to the teddycrepineau group:

    sudo usermod -aG teddycrepineau www-data
    

    The -aG flag ensures we append the group instead of overwriting any existing groups www-data belongs to.

  • Adjust socket permissions (optional but recommended)
    To make sure future uWSGI restarts create the socket with the right permissions, add this line to your uWSGI config file (like uwsgi.ini or your systemd service file):

    chmod-socket = 664
    

    If you need to fix the existing socket immediately, run:

    sudo chmod 664 /home/teddycrepineau/contoursandcolors/contoursandcolors.sock
    

    This gives read/write access to the owner and group (which now includes www-data).

  • Restart services to apply changes
    Restart Nginx to pick up the group membership change, and restart uWSGI to refresh the socket (if you updated its config):

    sudo systemctl restart nginx
    sudo systemctl restart your-uwsgi-service-name  # Replace with your actual uWSGI service name
    

Quick Extra Check

Make sure your project directory has permissions that let www-data traverse into it:

sudo chmod 755 /home/teddycrepineau/contoursandcolors

This lets all users (including www-data) enter the directory to access the socket.

内容的提问来源于stack exchange,提问作者Teddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:07:31