sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
systemctl start nginx.service
systemctl restart nginx.service
systemctl stop nginx.service
在浏览器输入localhost显示Welcon to nginx则安装成功
pip3 install uwsgi
查看/usr/local/bin 或者/usr/bin 中是否有uwsgi命令,因为我的系统中既安装了python2 页安装了python3 ,而我是用pip3安装的uwsgi 所以是安装在了python3的文件夹下的bin中,所以直接输入uwsgi系统找不到该命令,Linux的命令是放在/usr/bin 或/usr/local/bin中,只有在这两个文件中存在才能使用,需要把uwsgi软连接到/usr/bin下才能直接执行命令。
ln -s /usr/local/python3/bin/uwsgi /usr/bin
pip3 install Django
STATIC_URL='/static/'
STATICFILES_DIRS=(
os.path.join(BASE_DIR,"static"),
)
STATIC_ROOT='/usr/local/static'
#注意静态文件不要放在root文件夹下,读取的时候会出现权限问题导致网页没有样式,可以自己在根目录下创建一个文件夹存放。
命令:
python3 manage.py collectstatic
用命令whereis nginx 找到nginx 在/etc/nginx目录下,修改nginx.conf,修改之前最好备份一份。在nginx.conf 的http 中添加server模块。每一个server对应一个服务(app)。
server {
listen 8500; #端口
server_name 0.0.0.0:8500; #linux中设置为0.0.0.0
root /root/workspace/projects/python_project/VoiceBotService;#项目路径
client_max_body_size 100M;
#指定生成的日志路径
access_log /root/workspace/projects/python_project/VoiceBotService/nginx_access.log main;
error_log /root/workspace/projects/python_project/VoiceBotService/nginx_error.log error;
#项目静态文件路径即setting中的静态路径
location /static {
alias /usr/local/VoiceBotService/static/;
}
#与uwsgi通信的参数,uwsgi_pass必须和uwsgi.ini文件中法sock一致,必须指定include为uwsgi_params
location / {
uwsgi_pass unix:///usr/local/VoiceBotService/voicebotservice.scok;
include /etc/nginx/uwsgi_params;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
在项目manage.py 所在目录创建uwsgi.ini文件,添加内容如下 :
#uwsgi.ini file
[uwsgi]
# Django-related settings
#http = 0.0.0.0:8500
#socket必须与nginx中一致
socket = /usr/local/VoiceBotService/voicebotservice.scok
uid = root
pid = root
buffer-size = 65535
#项目路径
chdir = /root/workspace/projects/python_project/VoiceBotService
# Django s wsgi file
#项目wsgi.py路径appname.uwsgi
module = VoiceBotService.wsgi
pipfile=/root/workspace/projects/python_project/VoiceBotService/uwsgi.pid
# process-related settings
# master
master = true
vacuum=true
thunder-lock=true
harakiri=3000
post-buffering=4096
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
#日志路径
daemonize=/root/workspace/projects/python_project/VoiceBotService/uwsgi.log
在uwsgi.ini目录下执行命令:
uwsgi --ini uwsgi.ini
执行完命令后会在socket参数指定的目录下生成sockt文件
systemctl restart nginx.restart
每次更新完代码后都要执行5.6步骤。