我对NGINX很新,或者一般都是设置服务器。我正在阅读教程http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html,其中包含我正在尝试设置的网站。我在教程中使用套接字,但是,我无法使套接字工作。 nginx.conf看起来像这样。
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/althor/projects/Freebooks/freebooks.sock; # for a file socket
# server 127.0.0.1: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 8000;
# the domain name it will serve for
server_name 10.0.0.130; # 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/althor/projects/FreeBooks/media; # your Django project's media files - amend as required
}
location /static {
alias /home/althor/projects/FreeBooks/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 /home/althor/projects/FreeBooks/uwsgi_params; # the uwsgi_params file you installed
}
}
我正在做的命令是:
uwsgi --socket freebooks.sock --module FreeBooks.wsgi --chmod-socket=664
我的文件结构如下所示
-home -projects -FreeBooks freebooks_nginx.conf freebooks.sock = -FreeBooks WSGI
我没有收到任何类型的错误。当我转到10.0.0.130时,我得到的是对nginx的欢迎,对于0.0.0.0,127.0.0.1也是如此。除了我到达端口8000,我得到一个坏的nginx网关。任何帮助将非常感谢。
答案 0 :(得分:0)
删除你的"上游django"换行并替换你的uwsgi_pass行 uwsgi_pass unix:///home/althor/projects/Freebooks/freebooks.sock;
以便您的文件看起来像
server {
listen 8000;
server_name 10.0.0.130; # substitute your machine's IP address or FQDN
charset utf-8;
client_max_body_size 75M; # adjust to taste
location /media {
alias /home/althor/projects/FreeBooks/media;
}
location /static {
alias /home/althor/projects/FreeBooks/static;
}
location / {
include /home/althor/projects/FreeBooks/uwsgi_params;
uwsgi_pass unix:///home/althor/projects/Freebooks/freebooks.sock;
}
}
还要确保在运行uwsgi命令时实际创建了套接字文件,并且运行nginx的用户可以读取它(属性是正确的,但用户是否可以访问完整路径?)
答案 1 :(得分:0)
结果是权限问题。 NGINX没有写入套接字的权限。