如何在nginx和uwsgi上运行django项目

时间:2016-06-03 09:11:52

标签: python django ubuntu nginx uwsgi

我正在尝试使用nginx和uwsgi运行我的第一个Django项目。我遇到了nginx的问题。我在brouser中收到消息“无法连接。Firefox无法在localhost:8000建立与服务器的连接”。我按照这个链接的说明一切都很好uwsgi和安装nginx。然后我下载了uwsgi_params文件,并按照说明创建了mysite_nginx.conf文件。

这是mysite_nginx.conf文件:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.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 localhost; # 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/myproject/mysite/friends_plans/media;  # your Django      project's media files - amend as required
}

location /static {
    alias /home/ubuntu/myproject/mysite/friends_plans/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/ubuntu/myproject/mysite/uwsgi_params; # the    uwsgi_params file you installed
}
}

当我根据指示检查uwsgi时,它与服务器名称“localhost”和端口8000一起工作。我做了命令sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/ , python manage.py collectstatic , sudo /etc/init.d/nginx restart。在我的settinds.py中:STATIC_ROOT = "/home/ubuntu/myproject/mysite/friends_plans/static/"。有关静态文件的命令正常工作。但我无法设置与服务器的连接。你能否告诉我哪里有错误以及如何纠正?非常感谢你提前。

0 个答案:

没有答案