我正在尝试部署一个简单的 Django 项目,但总是失败。我正在按照这里的说明进行操作。
当我使用时python manage.py runserver 0.0.0.0:8000
,我可以看到我的网站正在运行:
在 virtualenv 中,我安装了 uWSGI:
pip install uwsgi
并写了test.py
:
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
#return ["Hello World"] # python2
跑步的时候uwsgi --http :8000 --wsgi-file test.py
可以看到
然后我安装了启动 Nginx:
sudo apt-get install nginx
sudo /etc/init.d/nginx start
我可以看到
然后写道mysite_nginx.conf
:
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 10.211.55.21; # 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 /path/to/your/mysite/media; # your Django project's media files - amend as required
#}
#location /static {
# alias /path/to/your/mysite/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/parallels/books/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
因为它只是一个简单的站点,所以我注释掉了媒体和静态路径,并且uwsgi_params
:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
目录:
并运行:
sudo ln -s ~/home/parallels/books/mysite/mysite_nginx.conf
/etc/nginx/sites-enabled/
mysite_nginx.conf
我可以看到/etc/nginx/sites-enabled/
:
然后运行:
sudo /etc/init.d/nginx restart
uwsgi --socket :8001 --wsgi-file test.py
我在我的网络浏览器中什么也看不到:
我不知道为什么,每当我尝试部署 Django 站点时,套接字部分都会失败。