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

Gunicorn未在项目目录生成myproject.sock文件问题求助

Troubleshooting: Gunicorn Not Generating myproject.sock File

Hey there, let’s work through this Gunicorn sock file issue step by step—I’ve run into this exact problem before when setting up Django with Gunicorn and Nginx, so here are the most common fixes to check first:

1. Ensure Your Gunicorn Service Config Is Complete

You only shared the [Unit] section of your /etc/systemd/system/gunicorn.service file. The [Service] and [Install] sections are critical for generating the sock file. Double-check that your full config looks something like this (replace placeholders with your actual paths and user info):

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=your_username
Group=www-data
WorkingDirectory=/home/your_username/your_project_folder
ExecStart=/home/your_username/your_project_env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/your_username/your_project_folder/myproject.sock your_project_name.wsgi:application

[Install]
WantedBy=multi-user.target

Pay extra attention to the --bind unix:/path/to/myproject.sock part—this path must point directly to your project directory, and the user running Gunicorn needs write access here.

2. Verify Directory Permissions

Gunicorn can’t create the sock file if it doesn’t have proper permissions for your project directory:

  • Check current permissions with: ls -ld /home/your_username/your_project_folder
  • If needed, adjust ownership to give your user and the web server group access: sudo chown -R your_username:www-data /home/your_username/your_project_folder

3. Check Gunicorn Service Status & Logs

Logs are your best friend here—they’ll tell you exactly why the sock file isn’t being created:

  1. First reload the systemd daemon and restart Gunicorn:
    sudo systemctl daemon-reload
    sudo systemctl restart gunicorn
    
  2. Check the service status for immediate errors:
    sudo systemctl status gunicorn
    
  3. For detailed logs, run:
    sudo journalctl -u gunicorn
    

Common issues here include typos in the virtual environment path, missing Django dependencies, or incorrect WSGI module names.

4. Test Gunicorn Directly

Bypass systemd to rule out service config issues:

  1. Activate your project’s virtual environment:
    source /home/your_username/your_project_env/bin/activate
    
  2. Run Gunicorn directly with the sock bind command:
    gunicorn --bind unix:/home/your_username/your_project_folder/myproject.sock your_project_name.wsgi:application
    

If this fails, you’ll get a clear error message (e.g., "module not found" or "permission denied") that points straight to the problem.

5. Rule Out SELinux Restrictions (If Applicable)

While Ubuntu 16.04 doesn’t enable SELinux by default, if you’ve turned it on, it might block Gunicorn from creating the sock file. Test this by temporarily disabling SELinux:

sudo setenforce 0

Restart Gunicorn—if the sock file appears, you’ll need to add a SELinux policy to allow the operation permanently.

Go through these steps one by one, and the logs will almost certainly point you to the exact issue. Let me know if you find a specific error message we can dig into further!

内容的提问来源于stack exchange,提问作者D.B

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:41:27