1.更新yum
sudo yum update
2.安装python3
#下载安装包。 wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz #解压安装包: tar -xf Python-3.7.4.tgz #进入文件夹: cd Python-3.7.4 #安装必备的包: yum install gcc-c++ yum install pcre pcre-devel yum install zlib zlib-devel yum install libffi-devel -y yum install openssl openssl-devel #指定安装目录: mkdir /usr/Python37#<=====创建目录 ./configure --prefix=/usr/Python37#<====绑定安装目录 make #<=====编译初始化 make install #<====安装 #创建软链接: ln -s /usr/Python37/bin/python3 /usr/bin/python3 ln -s /usr/Python37/bin/pip3 /usr/bin/pip3
3.python3中安装virtualenv并创建virtualenv环境
#安装vietuanenv pip install virtualenv #创建env环境,在env文件夹中运行: virtualenv name #进入虚拟环境: source name/bin/activate #退出虚拟环境: deactivate
4.在虚拟环境中上传django程序,并安装uwsgi
#django文件中会有一个文件叫requirements.txt, #上面显示所有程序需要的包,安装requirements.txt依赖 pip install -r requirements.txt #安装uwsgi pip install uwsgi
5.在django中新建uwsgi配置文件filename.ini,并编辑配置文件。
[uwsgi] # Django-related settings #此处为链接模式,nginx下位socket,直接访问的话改为http #如果使用阿里云的主机的话,这个地方的ip填内网IP socket=127.0.0.1:8000 # the base directory (full path) chdir=‘django路径’ module=my_blog.wsgi:application static-map = /static=collectedstatic master=true processes=4 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum=true daemonize=uwsgi_log.log pidfile=uwsgi_pid.pid pythonpath = /usr/Python37/site-packages
6.安装nginx
wget http://nginx.org/download/nginx-1.15.0.tar.gz(下载nginx) tar -zxvf nginx-1.15.0.tar.gz cd nginx-1.15.0 ./configure && make && make install
7.配置nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
在此附上我的nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream django { server 内网ip:8000; } server { listen 80; server_name 域名; location /media { alias /usr/local/envs/blog/django_blog/media; } location /static { alias /usr/local/envs/blog/django_blog/static; } location / { uwsgi_pass django; include /usr/local/envs/blog/django_blog/uwsgi_params; } } }
8.启动uwsgi
uwsgi: 通过配置文件blog_uwsgi.ini 启动uwsgi文件 uwsgi --ini blog_uwsgi.ini 查看uwsgi运行情况: ps aux|grep uwsgi uwsgi进程杀死命令: pkill -f uwsgi -9
9.启动nginx
start nginx :启动nginx
nginx -s reload :修改配置后重新加载生效
浙公网安备 33010602011771号