NGINX 与 uwsgi 和 django 连接被拒绝
Posted
技术标签:
【中文标题】NGINX 与 uwsgi 和 django 连接被拒绝【英文标题】:NGINX with uwsgi and django connection refused 【发布时间】:2015-04-30 01:34:01 【问题描述】:欢迎 ***ers。我一直在努力用 django 应用程序用 uwsgi 设置 nginx ......某处必须有一个小错误,但我找不到它。这是我来自 pastebin 的文件,其中包含与我的问题直接相关的文件以及控制台日志。如果有人可以看看并帮助我,我会非常感激。
artcolor_uwsgi.ini 文件
[uwsgi]
chdir = /home/seb/pypassion/artcolor/src/
module = artcolor.wsgi
home = /home/seb/pypassion/artcolor/artcolor_venv/
master = true
processes = 10
socket = /home/seb/pypassion/artcolor/src/artcolor.sock
#http-socket = :8001
#vacuum = true
artcolor_nginx.conf 文件
upstream django
server /home/seb/pypassion/artcolor/src/artcolor.sock; # for a file socket
#server 127.0.0.1:8001;
# configuration of the server
server
# the port your site will be served on
listen 8001;
server_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /home/seb/pypassion/artcolor/logs/nginx-access.log;
error_log /home/seb/pypassion/artcolor/logs/nginx-error.log;
# max upload size
client_max_body_size 1G; # adjust to taste
# Django media
location /media/
alias /home/seb/pypassion/artcolor/src/media/; # your Django project's media files - amend as required
location /static/
alias /home/seb/pypassion/artcolor/src/static/; # your Django project's static files - amend as required
# Finally, send all non-media requests to the Django server.
location /
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
wsgi.py 文件
import os
import sys
sys.path.append("/home/seb/pypassion/artcolor/src/")
sys.path.append("/home/seb/pypassion/artcolor/src/artcolor/")
sys.path = sys.path[::-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "artcolor.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我的控制台
(artcolor_venv)seb@debian:~/pypassion/artcolor/src$ uwsgi --ini artcolor_uwsgi.ini
[uWSGI] getting INI configuration from artcolor_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Fri Feb 27 11:48:45 2015] ***
compiled with version: 4.7.2 on 27 February 2015 11:00:34
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2
nodename: debian
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /home/seb/pypassion/artcolor/src
detected binary path: /home/seb/pypassion/artcolor/artcolor_venv/bin/uwsgi
chdir() to /home/seb/pypassion/artcolor/src/
your processes number limit is 63796
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/seb/pypassion/artcolor/src/artcolor.sock fd 3
Python version: 2.7.3 (default, Mar 13 2014, 11:26:58) [GCC 4.7.2]
Set PythonHome to /home/seb/pypassion/artcolor/artcolor_venv/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x20e9d30
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x20e9d30 pid: 14848 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 14848)
spawned uWSGI worker 1 (pid: 14849, cores: 1)
spawned uWSGI worker 2 (pid: 14850, cores: 1)
spawned uWSGI worker 3 (pid: 14851, cores: 1)
spawned uWSGI worker 4 (pid: 14852, cores: 1)
spawned uWSGI worker 5 (pid: 14853, cores: 1)
spawned uWSGI worker 6 (pid: 14854, cores: 1)
spawned uWSGI worker 7 (pid: 14855, cores: 1)
spawned uWSGI worker 8 (pid: 14856, cores: 1)
spawned uWSGI worker 9 (pid: 14857, cores: 1)
spawned uWSGI worker 10 (pid: 14858, cores: 1)
已解决 我将我的 nginx 文件链接到可用的站点,而不是因为我被认为启用了站点
【问题讨论】:
您如何尝试连接您的服务器? nginx 错误日志是怎么说的? “连接被拒绝”表示您尝试访问的端口未打开或前面可能有防火墙。我看到您的 nginx 正在侦听端口 8001。这也是您正在访问的端口吗?您是否还有另一台服务器(例如负载均衡器或缓存)从端口 80 代理到端口 8001? 首先我启动我的 nginx 然后我运行 uwsgi --ini artcolor_uwsgi.ini 下一步是运行 localhost:8001 (因为我的 nginx 正在侦听该端口)它应该将我重定向到我的artcolor.sock 我检查过,8001 上没有其他内容,我已将其更改为 9015 并重新启动了我的 nginx,但没有任何变化。 错误 400 是“错误请求”。您的网络浏览器发送了一个服务器不理解的请求。 我误解了 400 错误。它只是 ERR_CONNECTION_REFUSED 【参考方案1】:解决方案:
我设法解决了问题。
原因是链接 nginx.conf 文件错误。
我不小心链接到sites-available
,而不是我应该链接到sites-enabled
谢谢
【讨论】:
以上是关于NGINX 与 uwsgi 和 django 连接被拒绝的主要内容,如果未能解决你的问题,请参考以下文章
nginx,uwsgi,DJango,502 当 DEBUG=False,“上游过早关闭连接”