“.sock”不存在错误;连接()错误
Posted
技术标签:
【中文标题】“.sock”不存在错误;连接()错误【英文标题】:".sock" does not exist error; connect() error 【发布时间】:2018-10-03 04:44:05 【问题描述】:我正在尝试在 Linode 上的虚拟 Ubuntu 14.04 机器上设置 Mezzanine/Django 项目,但尝试在浏览器中导航到我的网站时出现“502 Bad Gateway error”。
我正在按照此处的说明进行操作:https://linode.com/docs/web-servers/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04。
我在/home/django/
中运行了git clone
,所以所有内容都在一个名为FOLDER
的文件夹中。
/home/django/
有这些目录:Env/
和 FOLDER/
。
这应该可以让您了解FOLDER/
树的样子:
FOLDER
- product_blog
-- product_blog
--- settings.py
--- wsgi.py
-- manage.py
在我的settings.py
中,我有:
ALLOWED_HOSTS = ["PUBLIC IP OF MY LINODE UBUNTU INSTANCE HERE"]
wsgi.py
有这个:
"""
WSGI config for product_blog project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from mezzanine.utils.conf import real_project_name
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"%s.settings" % real_project_name("product_blog"))
application = get_wsgi_application()
/etc/uwsgi/sites/product_blog.ini
有这个:
[uwsgi]
project = product_blog
base = /home/django
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 2
socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true
/etc/init/uwsgi.conf
有这个:
description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]
respawn
env UWSGI=/usr/local/bin/uwsgi
env LOGTO=/var/log/uwsgi.log
exec $UWSGI --master --emperor /etc/uwsgi/sites --die-on-term --uid django --gid www-data --logto $LOGTO
/etc/nginx/sites-available/product_blog
有这个:
server
listen 80;
server_name mydomain.com;
location = /favicon.ico access_log off; log_not_found off;
location /static/
root /home/django/FOLDER;
location /
include uwsgi_params;
uwsgi_pass unix:/home/django/FOLDER/product_blog/product_blog.sock;
当我转到 Linode 框的 IP 地址时,我看到 502 Bad Gateway 错误。
/var/log/uwsgi.log
有这个...
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from product_blog.ini
*** Starting uWSGI 2.0.17 (64bit) on [Sun Apr 22 17:17:56 2018] ***
compiled with version: 4.8.4 on 22 April 2018 19:53:45
os: Linux-4.15.12-x86_64-linode105 #1 SMP Thu Mar 22 02:13:40 UTC 2018
nodename: ubuntu-linode
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/django/product_blog
chdir(): No such file or directory [core/uwsgi.c line 2629]
chdir(): No such file or directory [core/uwsgi.c line 1644]
Sun Apr 22 17:17:56 2018 - [emperor] curse the uwsgi instance product_blog.ini (pid: 4238)
Sun Apr 22 17:17:59 2018 - [emperor] removed uwsgi instance product_blog.ini
/var/log/nginx/error.log
有这个(识别信息已删除):
2018/04/22 17:18:14 [crit] 3953#0: *9 connect() to unix:/home/django/FOLDER/product_blog/product_blog.sock failed (2: No such file or directory) while connecting to upstream, client: 73.49.35.42, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/django/FOLDER/product_blog/product_blog.sock:", host: "ADDRESS TO LINODE BOX"
product_blog.sock
似乎应该在我的目录中的某个位置,但它不存在。如何修复 502 错误,以便我可以将浏览器导航到 Linode 框的地址并查看正常工作的网站?
【问题讨论】:
【参考方案1】:socket文件应该是由uWSGI创建的。但是 uWSGI 日志告诉您它无法启动,因为它无法 cd 到您在 product_blog.ini 中指定的目录,/home/django/product_blog
。
我不知道FOLDER
是否是占位符,但无论如何您似乎没有将它包含在该路径中。我想应该是:
chdir = %(base)/FOLDER/%(project)
...
socket = %(base)/FOLDER/%(project)/%(project).sock
【讨论】:
以上是关于“.sock”不存在错误;连接()错误的主要内容,如果未能解决你的问题,请参考以下文章
错误信息:无法连接: SQL Server 不可用或不存在。
错误 12545:连接失败,因为尝试连接 sqlplus 时目标主机或对象不存在
sybase_connect() 错误 - “无法连接:Adaptive Server 不可用或不存在”
PHP/PDO 错误:SQLSTATE[HY000] 无法连接:Adaptive Server 不可用或不存在(严重性 9)