python - Gunicorn 未在 AWS EC2 上创建 .sock 文件

标签 python django nginx amazon-ec2 gunicorn

我坚持按照本教程创建 Django Web 应用程序: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#check-for-the-gunicorn-socket-file

我想我已经阅读了所有相关问题:

django gunicorn sock file not created by wsgi

Gunicorn not generating sock file

https://github.com/benoitc/gunicorn/issues/1166

他们都没有帮助。

我完全按照描述执行每个步骤,但仍然没有创建 myapp.sock 文件。

主项目目录为/home/ubuntu/puchalatravel 其内容:

ubuntu@ip-172-31-35-104:~/puchalatravel$ ls -l
total 60
-rw-r--r-- 1 ubuntu ubuntu   40960 Sep  4 09:37 db.sqlite3
-rwxrwxr-x 1 ubuntu ubuntu     545 Sep  4 07:42 manage.py
drwxrwxr-x 3 ubuntu www-data  4096 Sep  4 09:32 puchalatravel
drwxrwxr-x 4 ubuntu ubuntu    4096 Sep  4 07:41 puchalatravelenv
drwxrwxr-x 3 ubuntu ubuntu    4096 Sep  4 09:34 static

访问文件夹:

ubuntu@ip-172-31-35-104:~$ ls -l
total 1616
drwxrwxr-x 4 ubuntu ubuntu      4096 Aug 30 07:25 eb-virt
-rw-rw-r-- 1 ubuntu ubuntu   1642522 Aug 30 07:11 get-pip.py
drwxrwxr-x 6 ubuntu www-data    4096 Sep  4 09:37 puchalatravel

/etc/systemd/system/gunicorn.service的内容

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

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/puchalatravel
ExecStart=/home/ubuntu/puchalatravel/puchalatravelenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/puchalatravel/puchalatravel.sock puchalatravel.wsgi:application

[Install]
WantedBy=multi-user.target

/etc/nginx/sites-available/puchalatravel 的内容

server {                                                                                                                                                                                                                                 sserver {
listen 8000;
    server_name ec2-18-188-249-6.us-east-2.compute.amazonaws.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/puchalatravel;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/puchalatravel/puchalatravel.sock;
    }
}

我跑了

pkill gunicorn
sudo systemctl daemon-reload
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo systemctl restart nginx

多次,没有任何效果。

sudo systemctl status Gunicorn 的输出

● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-09-04 09:56:51 UTC; 18min ago
Main PID: 19906 (code=exited, status=1/FAILURE)

Sep 04 09:56:46 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:46 +0000] [19906] [INFO] Starting gunicorn 19.9.0
Sep 04 09:56:46 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:46 +0000] [19906] [ERROR] Retrying in 1 second.
Sep 04 09:56:47 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:47 +0000] [19906] [ERROR] Retrying in 1 second.
Sep 04 09:56:48 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:48 +0000] [19906] [ERROR] Retrying in 1 second.
Sep 04 09:56:49 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:49 +0000] [19906] [ERROR] Retrying in 1 second.
Sep 04 09:56:50 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:50 +0000] [19906] [ERROR] Retrying in 1 second.
Sep 04 09:56:51 ip-172-31-35-104 gunicorn[19906]: [2018-09-04 09:56:51 +0000] [19906] [ERROR] Can't connect to /home/puchalatravel/puchalatravel.sock
Sep 04 09:56:51 ip-172-31-35-104 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Sep 04 09:56:51 ip-172-31-35-104 systemd[1]: gunicorn.service: Unit entered failed state.
Sep 04 09:56:51 ip-172-31-35-104 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

这可能与 AWS EC2 设置有关吗? Gunicorn 直接将页面提供给端口 8000,但不通过套接字,因为它尚未创建。

最佳答案

您的gunicorn.service 文件将gunicorn 配置为在“/home/puchalatravel/puchalatravel.sock”而不是“/home/ubuntu/puchalatravel/puchalatravel.sock”中创建文件。

关于python - Gunicorn 未在 AWS EC2 上创建 .sock 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52163992/

相关文章:

python - 在 MySQL 子查询中使用 Python 变量

python - Python从文件中读取数据 block

python - Django "ImproperlyConfigured",但并非总是如此

python - 如何围绕现有产品构建测试套件?

java - 当执行到 Tomcat 的 proxy_pass 时,Nginx 如何将子域添加为参数

node.js - Node 服务器中的 Express-rate-limit 与 NGINX

php - CWP : SSL + WebSocket + Ngnix

python - 在 asyncio 事件循环中运行协程和线程 : Errors while exiting

python - Django 'bool' 对象没有属性 '_committed'

python - 代码出现故障?