标签:quit create path emd run tar 数据库 you manage
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
浏览器访问:
http://xiangmu.buy360.xyz:443
浏览器访问:
http://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 = true
processes = 5
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 660
vacuum = 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/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=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
测试:
浏览器地址栏:http://xiangmu.buy360.xyz
ngnix+uwsgi+django+python+mysql环境部署
标签:quit create path emd run tar 数据库 you manage
原文地址:http://blog.51cto.com/13523982/2064072