如果我使用uwsgi --ini kb_uwsgi.ini --http :80
运行uwsgi,则会给我一个错误:
[uWSGI] getting INI configuration from kb_uwsgi.ini
*** Starting uWSGI 2.0.14 (64bit) on [Thu Jan 26 12:34:51 2017] ***
compiled with version: 5.4.0 20160609 on 06 January 2017 11:55:37
os: Linux-4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
nodename: ip-172-31-16-133
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/ubuntu/webapps/kenyabuzz
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/ubuntu/webapps/kenyabuzz
your processes number limit is 64137
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)
bind(): Permission denied [core/socket.c line 769]
如果我在命令前加sudo
或使用端口:8000
,例如uwsgi --ini kb_uwsgi.ini --http :8000
现在我尝试使用nginx和uwsgi使网站生效我得到a 502 Bad Gateway nginx/1.10.0 (Ubuntu)
nginx工作正常,因为favicon加载并且我可以使用\static\...
访问静态文件我知道这是Django有问题渲染。我已经尝试加载uwsgi --ini kb_uwsgi.ini --http :8000
而不加载djangoenv它仍然加载。
kb_uwsgi.ini
文件如下所示:
# kb_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/ubuntu/webapps/kenyabuzz
# Django's wsgi file
module = kb.wsgi
# the virtualenv (full path)
home = /home/ubuntu/webapps/djangoenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /tmp/kb.sock
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
和kb_nginx.conf
一样
# kb.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/kb.sock; # for a file socket
#server 0.0.0.0:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name kenyabuzz.nation.news; # 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/webapps/kenyabuzz/kb/media; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
}
location /favicon.ico {
alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/webapps/kenyabuzz/uwsgi_params; # the uwsgi_params file you installed
}
}
日志包含:
2017/01/26 13:02:17 [crit] 4065#4065: *10 connect() to unix:///tmp/kb.sock failed (2: No such file or directory) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/kb.sock:", host: "kenyabuzz.nation.news"
uwsgi应自动创建文件(确实如此),并在使用上面的示例关闭文件时将其删除。
感谢您的任何帮助。
更新
编辑.ini文件并取消注释chmod-socket=664
kb.sock文件在重新启动nginx时仍未创建。
答案 0 :(得分:1)
对于nginx:
# kb.conf
...
# the upstream component nginx needs to connect to
upstream django {
server unix:/tmp/kb.sock;
}
...
对于uWSGI:
# kb_uwsgi.ini file
[uwsgi]
...
# the socket (use the full path to be safe
socket = /tmp/kb.sock
chmod-socket = 666
...