一、安装Nginx
sudo apt-get install nginx
更改/etc/nginx/sites-enabled/default文件
添加内容:
server
{
listen 8080;
#server_name 127.0.0.1
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
location /
{
include uwsgi_params;
uwsgi_pass 0.0.0.0:8000;
uwsgi_read_timeout 2;
}
location /static
{
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/demo/myweb/static/;
}
}
二、安装uwsgi
sudo apt-get install python3-dev
sudo apt-get install python3-pip
python3 -m pip install setuptools
python3 -m pip install uwsgi
pip3 list查看安装情况
三、安装django
sudo apt install python3-django
python3 -m pip install django
四、测试django安装是否成功
django-admin startproject myweb
在myweb文件夹创建 myweb_uwsgi.ini
内容如下:
# myweb_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8000
# the base directory (full path)
chdir = /home/demo/myweb
# Django s wsgi file
module = myweb.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
五、启动django服务
uwsgi --ini myweb_uwsgi.ini