uWSGI、nginx、django unix 套接字不工作
uWSGI, nginx, django unix sockets not working
我有一个 Django 应用程序。我似乎无法让 nginx 正确地提供静态文件,但这不是这个问题。
当前的问题是,当遵循本指南时:https://gist.github.com/evildmp/3094281
我尝试使用 unix 套接字而不是 web 套接字。
例如
server unix:///tmp/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket
使用 /tmp/uwsgi.sock 套接字而不是 127.0.0.1:8001 网络端口套接字。
问题是,当我使用网络端口套接字并导航到 domainname.com:8001 时,我到达了由 uWSGI 提供服务的网站,但是没有加载任何静态文件。所以这意味着至少 uwsgi 在工作。但是当我切换到文件套接字时,我什至无法让它工作。
我做错了什么?
这是我的 nginx.conf:
# nginx.conf
upstream django {
# connect to this socket
# server unix:///tmp/uwsgi.sock; # for a file socket (TRYING TO USE)
server 127.0.0.1:8001; # for a web port socket (RATHER THAN THIS)
}
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name .cshenkan.com; # substitute your machine's IP address or FQDN
charset utf-8;
#Max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/sasite-rewrite/media; # your Django pro$
}
location /static {
alias /home/ubuntu/sasite-rewrite/static; # your Django pro$
}
location /assets {
alias /home/ubuntu/sasite-rewrite/assets
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # or the uwsgi_params you installe$
}
}
还有我的 base.py 设置文件片段:
STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
normpath(join(SITE_ROOT, 'static')),
normpath(join(SITE_ROOT, 'assets')),
)
以及我如何 运行 uwsgi 使用网络套接字时:
uwsgi --http :8001 --chdir /home/ubuntu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
以及我在使用 unix 套接字时如何 运行 它:
uwsgi --socket /tmp/uwsgi.sock --chdir /home/ubutnu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
我只是在使用 unix 套接字时似乎无法让它工作。
我也无法让 nginx 提供正确的静态文件,例如,如果我将一个文件添加到名为 1.png 或 1.txt 的媒体目录并尝试使用 [=61= 访问它们]:8000/media/1.png 我总是挂起或服务器错误没有响应。
我做错了什么?
如何让 unix 套接字正常工作?我使用的命令是否正确?
我也不明白这个,当我使用网络套接字时,我可以连接到 domainname.com:8001 并获得没有静态文件的页面,它看起来像废话但是从 uwsgi 加载。但是对于 unix 套接字,我不知道如何访问 uwsgi 服务的页面以查看它是否适用于 unix 套接字。在我开始让 nginx 工作之前,我需要解决这个问题,因为我尝试将 web 套接字与 nginx 一起使用,但仍然没有成功,我希望一旦我的 unix 套接字设置正确,nginx 会更好地工作。
您可以提供任何建议或示例吗?将不胜感激,我是一个长期的 django 程序员,但我自己很少部署这些站点。所以我真的很挣扎。
非常感谢任何帮助,谢谢。
今天我在使用 NGINX + Socket Unix for uwsgi 协议时遇到了同样的问题。
我发现 NGINX 1.8 版本有问题。
尝试安装可通过 UNIX SOCKET 运行的 1.10 版。
如果您使用 open-SuSE,您可以在这里获取 rpm:
或者,直接在nginx官方下载区:
我有一个 Django 应用程序。我似乎无法让 nginx 正确地提供静态文件,但这不是这个问题。
当前的问题是,当遵循本指南时:https://gist.github.com/evildmp/3094281
我尝试使用 unix 套接字而不是 web 套接字。
例如
server unix:///tmp/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket
使用 /tmp/uwsgi.sock 套接字而不是 127.0.0.1:8001 网络端口套接字。
问题是,当我使用网络端口套接字并导航到 domainname.com:8001 时,我到达了由 uWSGI 提供服务的网站,但是没有加载任何静态文件。所以这意味着至少 uwsgi 在工作。但是当我切换到文件套接字时,我什至无法让它工作。
我做错了什么?
这是我的 nginx.conf:
# nginx.conf
upstream django {
# connect to this socket
# server unix:///tmp/uwsgi.sock; # for a file socket (TRYING TO USE)
server 127.0.0.1:8001; # for a web port socket (RATHER THAN THIS)
}
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name .cshenkan.com; # substitute your machine's IP address or FQDN
charset utf-8;
#Max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/sasite-rewrite/media; # your Django pro$
}
location /static {
alias /home/ubuntu/sasite-rewrite/static; # your Django pro$
}
location /assets {
alias /home/ubuntu/sasite-rewrite/assets
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # or the uwsgi_params you installe$
}
}
还有我的 base.py 设置文件片段:
STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
normpath(join(SITE_ROOT, 'static')),
normpath(join(SITE_ROOT, 'assets')),
)
以及我如何 运行 uwsgi 使用网络套接字时:
uwsgi --http :8001 --chdir /home/ubuntu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
以及我在使用 unix 套接字时如何 运行 它:
uwsgi --socket /tmp/uwsgi.sock --chdir /home/ubutnu/sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
我只是在使用 unix 套接字时似乎无法让它工作。
我也无法让 nginx 提供正确的静态文件,例如,如果我将一个文件添加到名为 1.png 或 1.txt 的媒体目录并尝试使用 [=61= 访问它们]:8000/media/1.png 我总是挂起或服务器错误没有响应。
我做错了什么?
如何让 unix 套接字正常工作?我使用的命令是否正确?
我也不明白这个,当我使用网络套接字时,我可以连接到 domainname.com:8001 并获得没有静态文件的页面,它看起来像废话但是从 uwsgi 加载。但是对于 unix 套接字,我不知道如何访问 uwsgi 服务的页面以查看它是否适用于 unix 套接字。在我开始让 nginx 工作之前,我需要解决这个问题,因为我尝试将 web 套接字与 nginx 一起使用,但仍然没有成功,我希望一旦我的 unix 套接字设置正确,nginx 会更好地工作。
您可以提供任何建议或示例吗?将不胜感激,我是一个长期的 django 程序员,但我自己很少部署这些站点。所以我真的很挣扎。
非常感谢任何帮助,谢谢。
今天我在使用 NGINX + Socket Unix for uwsgi 协议时遇到了同样的问题。 我发现 NGINX 1.8 版本有问题。
尝试安装可通过 UNIX SOCKET 运行的 1.10 版。
如果您使用 open-SuSE,您可以在这里获取 rpm:
或者,直接在nginx官方下载区: