配置nginx静态服务器
安装nginx
https://www.cnblogs.com/reboot777/p/7226365.html
启动 nginx
cd /usr/local/nginx
sudo sbin/nginx
sudo sbin/nginx -s stop
ps aux|grep nginx 查看nginx进程状态
BASE_DIR是项目根目录,我对应的是D:\Pycharm\wechat_huoyun,那么STATIC_ROOT对应的就是
STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(BASE_DIR)),'front_end/static')
python manage.py collectstatic
debug改为False
配置uwsgi动态服务器
1.pip install uwsgi
2.新建uwsgi.ini文件
3.配置uwsgi.ini文件
[uwsgi]
#使用nginx连接时使用,Django程序所在服务器地址
socket=127.0.0.1:3309
#直接做web服务器使用,Django程序所在服务器地址
#http=127.0.0.1:8000
#项目目录
chdir=/home/python/Desktop/meiduo/meiduo_mall
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=meiduo_mall/wsgi.py
# 进程数
processes=4
# 线程数
threads=2
# uwsgi服务器的角色
master=True
# 存放进程编号的文件
pidfile=uwsgi.pid
# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的
daemonize=uwsgi.log
# 指定依赖的虚拟环境
virtualenv=/home/python/.virtualenvs/xxx(虚拟环境名称)
4.进入nginx安装目录,找到nginx.conf,进行配置
使用sudo vim nginx.conf
# 动态url设置地址设置
40 server {
41 listen 8000;
42 # 只是给ip取个名字,也可以用ip:port的方式
43 # server_name 127.0.0.1;
44
45 location / {
46 uwsgi_pass 127.0.0.1:3309;
47 include uwsgi_params;
48 }
49
50 }
# 静态文件地址设置
53 server {
54 listen 80;
55 # 只是给ip取个名字,也可以用ip:port的方式
56 server_name 127.0.0.1;
57 #charset koi8-r;
58
59 #access_log logs/host.access.log main;
60
61 # location / {
62 # root html;
63 # index index.html index.htm;
64 # }
location / {
78 root /home/python/Desktop/meiduo/front_end;
79 index index.html index.htm;
80 }