无法生成部署 Django 项目的 unix 套接字
Can't generate unix socket deploying django project
我正在尝试部署我的第一个 django 项目,我在 linode 服务器上使用 uwsgi 和 nginx。
基本上我按照接下来的步骤。
在 /etc/uwsgi/apps-available/ 上为我的项目创建 uwsgi 配置文件,并在 /etc/uwsgi/apps-enabled/:
上创建符号 link
[uwsgi]
plugins = http,python
env = DJANGO_SETTINGS_MODULE=app.settings
chdir = /opt/deploy/.virtualenvs/test_app/test/
home = /opt/deploy/.virtualenvs/test_app/
module = django.core.handlers.wsgi:WSGIHandler()
processes = 4
idle = 3600
touch-reload = /opt/deploy/.virtualenvs/test_app/test/app/local_settings.py
在 /etc/nginx/sites-available/ 上创建我的 nginx 配置文件并在 cd nginx/sites-enabled/ 中创建符号 link,这是我的 nginx 文件:
server {
server_name www.test.com;
rewrite ^(.*) http://test.com permanent;
}
server {
listen 80;
server_name test.com;
charset utf-8;
client_max_body_size 10m;
client_body_buffer_size 128k;
# serve static files
location /static/ {
alias /opt/deploy/.virtualenvs/test_app/test/app/static/;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/app/test.sock;
}
}
重启uwsgi和nginx。
我希望在 run/uwsgi/app/ 上找到文件 test.sock,但文件没有创建。当看到 nignx 错误日志时,我有这一行:
2015/10/02 01:47:49 [crit] 8967#0: *51 connect() to unix:/run/uwsgi/app/test.sock failed (2: No such file or directory) while connecting to upstream, client: 181.135.143.435, server: test.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/app/test.sock:", host: "test.com"
为什么我可以生成 uwsgi 文件?非常感谢,我知道这可能是一个愚蠢的问题,但在做这个之前写了很多教程,但找不到任何解决方案..谢谢你.
您的配置中缺少一部分。这是来自我的服务器的工作配置:
upstream django-myhome {
server unix:///home/myhome/myhome/myhome.sock; # for a file socket
}
server
location / {
uwsgi_pass django-myhome;
include /home/myhome/myhome/uwsgi_params; # the uwsgi_params file you installed
}
还要确保您拥有创建 .sock 文件的正确权限
也许您需要一些特殊权限才能在位置 /run/uwsgi/app/ 上生成套接字文件。如果放在/tmp/test.sock中,应该能正确生成socket。
我正在尝试部署我的第一个 django 项目,我在 linode 服务器上使用 uwsgi 和 nginx。 基本上我按照接下来的步骤。
在 /etc/uwsgi/apps-available/ 上为我的项目创建 uwsgi 配置文件,并在 /etc/uwsgi/apps-enabled/:
上创建符号 link[uwsgi] plugins = http,python env = DJANGO_SETTINGS_MODULE=app.settings chdir = /opt/deploy/.virtualenvs/test_app/test/ home = /opt/deploy/.virtualenvs/test_app/ module = django.core.handlers.wsgi:WSGIHandler() processes = 4 idle = 3600 touch-reload = /opt/deploy/.virtualenvs/test_app/test/app/local_settings.py
在 /etc/nginx/sites-available/ 上创建我的 nginx 配置文件并在 cd nginx/sites-enabled/ 中创建符号 link,这是我的 nginx 文件:
server { server_name www.test.com; rewrite ^(.*) http://test.com permanent; } server { listen 80; server_name test.com; charset utf-8; client_max_body_size 10m; client_body_buffer_size 128k; # serve static files location /static/ { alias /opt/deploy/.virtualenvs/test_app/test/app/static/; } location / { include uwsgi_params; uwsgi_pass unix:/run/uwsgi/app/test.sock; } }
重启uwsgi和nginx。
我希望在 run/uwsgi/app/ 上找到文件 test.sock,但文件没有创建。当看到 nignx 错误日志时,我有这一行:
2015/10/02 01:47:49 [crit] 8967#0: *51 connect() to unix:/run/uwsgi/app/test.sock failed (2: No such file or directory) while connecting to upstream, client: 181.135.143.435, server: test.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/app/test.sock:", host: "test.com"
为什么我可以生成 uwsgi 文件?非常感谢,我知道这可能是一个愚蠢的问题,但在做这个之前写了很多教程,但找不到任何解决方案..谢谢你.
您的配置中缺少一部分。这是来自我的服务器的工作配置:
upstream django-myhome {
server unix:///home/myhome/myhome/myhome.sock; # for a file socket
}
server
location / {
uwsgi_pass django-myhome;
include /home/myhome/myhome/uwsgi_params; # the uwsgi_params file you installed
}
还要确保您拥有创建 .sock 文件的正确权限
也许您需要一些特殊权限才能在位置 /run/uwsgi/app/ 上生成套接字文件。如果放在/tmp/test.sock中,应该能正确生成socket。