摘要:本文主要向大家介绍了Python语言之ngnix+uwsgi+django+python+mysql环境部署,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。
本文主要向大家介绍了Python语言之ngnix+uwsgi+django+python+mysql环境部署,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。
django 一个python的web框架flask和djangouwsgi一个Python的容器nginx 一个web服务器 可以做web容器的前端client--->nginx(80)--->uwsgi(开端口5000)--->web页面virtualenv virtualenvwrapper python开发虚拟环境安装python3: 下载python3.6 去官网下载 #xz -d 压缩包.xz 准备环境: #yum install zlib* openssl* readline* sqlite* -y 安装python3 # cd Python-3.6.4 # ./configure --prefix=/usr/local/python3.6 && make && make install # rm -rf /usr/bin/python # ln -s /usr/local/python3.6/bin/python3 /usr/bin/python 处理yum(python升级之后yum就不能用了,他默认用的2.7) # vim /usr/bin/yum 把解释器改成2.7 # !/usr/bin/python2.7 给pip做软连接: # ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip # vim ~/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/python3.6/bin/ #source ~/.bash_profile安装django # pip install django==1.10创建django项目:firstsite #cd ~ #django-admin.py startproject firstsite #cd ~/firstsite同步数据库: #./manage.py migrate #./manage.py createsuperuser设置静态文件目录: # vim firstsite/settings.py //先找到STATIC关键字,追加下面一行 STATIC_ROOT = os.path.join(BASE_DIR, "static/") #./manage.py collectstatic测试django是否可用: #./manage.py runserver 0.0.0.0:443 浏览器访问: //xiangmu.buy360.xyz:443 浏览器访问: //xiangmu.buy360.xyz:443/admin安装uwsgi: #pip install uwsgi测试uwsgi: # uwsgi --http :443 --chdir /root/firstsite -w firstsite.wsgi --http :端口 --chdri 项目目录 -w wsgi模块创建uwsgi配置文件:#mkdir -p /etc/uwsgi/sites# vim /etc/uwsgi/sites/firstsite.ini [uwsgi]project = firstsite //项目名称username = root //运行用户base = /%(username)/ //项目目录的上级目录chdir = %(base)/%(project) //项目目录module = %(project).wsgi:application master = trueprocesses = 5uid = %(username)socket = /run/uwsgi/%(project).sockchown-socket = %(username):nginxchmod-socket = 660vacuum = true创建uwsgi启动配置文件:# vim /etc/systemd/system/uwsgi.service[Unit]Description=uWSGI Emperor service[Service]ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown root:nginx /run/uwsgi'ExecStart=/usr/local/python3.6/bin/uwsgi --emperor /etc/uwsgi/sitesRestart=alwaysKillSignal=SIGQUITType=notifyNotifyAccess=all[Install]WantedBy=multi-user.target下面两步不做会启动服务不成功:#mkdir /root/uwsgi#ln -s /usr/local/python3.6/bin/uwsgi /root/uwsgi/uwsgi安装nginx:#yum install nginx配置nginx:# vim /etc/nginx/nginx.conf 添加如下虚拟主机配置server { listen 80; server_name firstsite.com www.youngfit.cn; location = favicon.ico { access_log off; log_not_found off; } location /static/ { root /root/firstsite; } location / { include uwsgi_params; uwsgi_pass unix:/run/uwsgi/firstsite.sock; }}测试Nginx配置文件语法正确性: # nginx -t设置权限:# usermod -a -G root nginx# chmod 710 /root启动nginx和uwsgi服务: #systemctl start nginx #systemctl start uwsgi
本文由职坐标整理并发布,希望对同学们学习Python有所帮助,更多内容请关注职坐标编程语言Python频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号