博客
关于我
nginx+uwsgi+django
阅读量:790 次
发布时间:2023-02-15

本文共 9914 字,大约阅读时间需要 33 分钟。

???CentOS 7???uWSGI?Nginx???Django????

??

Django ???????? Web ????????? Python ????????????Django ?????????????????????????????????????????????????? Web ?????????????????? CentOS 7 ????????????????? Django ?????????? uWSGI ????????????????Nginx ?????? uWSGI???????????????????????????????

???????

????????????????? CentOS 7 ??????????? root ??????? sudo ??????????????????????????????????????????????? Django?????????????????????????????????????????????????????????????????????????? uWSGI ?????????????????????????? HTTP ????????????????????? Python ?????????? uWSGI ???? Nginx??????????????????????????

????? VirtualEnv ? VirtualEnvWrapper

??????????????????? Django ????????????????????????? Python ????? virtualenv??? virtualenvwrapper???? virtualenv ??????????????????? pip?Python ????????????????? pip????????? EPEL ???????????????????

sudo yum install epel-release

???? EPEL???????????????? pip?

sudo yum install python-pip

???????? pip?????????????????? virtualenv ? virtualenvwrapper?

sudo pip install virtualenv virtualenvwrapper

??????????????????? shell ????????? virtualenvwrapper ?????????????????????????????? Env ?????????????????????? WORKON_HOME ?????????????????????? shell ?????????????????????

??????????? shell ?????????????????

echo "export WORKON_HOME=~/Env" >> ~/.bashrcecho "source /usr/bin/virtualenvwrapper.sh" >> ~/.bashrc

???????? shell ???????????????????????

source ~/.bashrc

???????? home ????????? Env ???????????????

?? Django ??

???????????????????????????????? Django?????????

???????

???????? virtualenvwrapper ???????????????????????????????????????????????????????????

mkvirtualenv firstsite

???????????????? Python ? pip???????????????????????????????firstsite?user @ hostname??$????????????????????????????????????????????????????????????????????????????????

????????? Django ????????????????????????????????? sudo ?????? pip?

pip install django

?? Django ???????????????????????????

cd ~django-admin.py startproject firstsite

????????? firstsite ????????????????????????????????????????????????????

????????????????????????????

cd ~/firstsite

???????????????????? SQLite ???????????????????????????????????????????

./manage.py migrate

????????????????? db.sqlite 3 ???????????????????????????????

./manage.py createsuperuser

???????????????????????????????????????

?????????????????????

nano firstsite/settings.py

??????? Nginx ??????????????????????????????????? Nginx ???????????????????????????? Django ????????????????????????????????????????

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

?????????????????????????????????????????????

./manage.py collectstatic

?????????????????????????????????

./manage.py runserver 0.0.0.0:8080

????? 8080 ??????????????????????? IP ??????? 8080?

???????

?????????????????????????????????????????????

????????????????????????????????????? Django?

cd ~mkvirtualenv secondsitepip install django

???????????????????????? Django ??????????????????????????????????

???????????????

django-admin.py startproject secondsitecd ~/secondsite

????????????????

./manage.py migrate./manage.py createsuperuser

???????

nano secondsite/settings.py

????????? [uwsgi] ??????????????????????????????????????????????????????????????????? project ??????????????????????????????? base ???????????????????????

[uwsgi]    project = firstsite    username = user    base = /home/%(username)

?????????? uWSGI????????????????????? chdir ???????????????????? %(variable_name) ??????????????????????????????????

??????

??????????????? Django ??????????????????????

deactivate

??????????? Django ?????????????????????????? workon ?????????

workon firstsite

???

workon secondsite

???????????????????

deactivate

?? uWSGI ???????

??????? Django ??????????????? uWSGI?uWSGI ????????????????? WSGI ??????????????????????????????? Ubuntu 14.04 ??? uWSGI ? Nginx ????

?? uWSGI

???????????????????????? uWSGI????????? Django ???????????? uWSGI ???????????? Python ????????????????????????????? yum?

sudo yum install python-devel gcc

?????????????????????????????? uWSGI?

sudo pip install uwsgi

?????????????????????????????????????????????????????????????

uwsgi --http :8080 --home /home/user/Env/firstsite --chdir /home/user/firstsite -w firstsite.wsgi

???????? uWSGI ?????? ?/ Env ?????????????????????????????????????? wsgi.py ???????????????????????? 8080 ??? HTTP ???????????????????? IP ???????8080????????????/ admin ??????????? ??????????????????? CTRL-C?

??????

?????? uWSGI ?????????????????????????????Emperor????? uWSGI????????????????????????????????

??????????????????????????????????????? / etc / uwsgi / sites ???????????????????????????

sudo mkdir -p /etc/uwsgi/sitescd /etc/uwsgi/sites

???????????????????????????????????????????uWSGI ????????????????????????????? .ini ???

???????????????????????????

sudo nano firstsite.ini

????????? [uwsgi] ??????????????????????????????????????????????????????????????????? project ??????????????????????????????? base ???????????????????????

[uwsgi]    project = firstsite    username = user    base = /home/%(username)

?????????? uWSGI????????????????????? chdir ???????????????????? %(variable_name) ??????????????????????????????????

[uwsgi]    project = firstsite    username = user    base = /home/%(username)    chdir = %(base)/%(project)    home = %(base)/Env/%(project)    module = %(project).wsgi:application    master = true    processes = 5

?????????? uWSGI ????????????? uWSGI ?????????? HTTP ??????????????? Nginx ????????????????

???????????????????????????????????? Unix ????????????????????????????? HTTP????? uWSGI ? uwsgi ????????????????????????????Nginx ???? uwsgi ???????????????????

???????????????????????????????????????? Web ????????????????? / run / uwsgi ??????????????uWSGI ? Nginx ???????????? vacuum ?????????????????????

[uwsgi]    project = firstsite    username = user    base = /home/%(username)    chdir = %(base)/%(project)    home = %(base)/Env/%(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 ???????????????

??????????????????????????????????????????????????

sudo cp /etc/uwsgi/sites/firstsite.ini /etc/uwsgi/sites/secondsite.ini

??????????????????

sudo nano /etc/uwsgi/sites/secondsite.ini

???????????????????????????????????????????????????????

[uwsgi]    project = firstsite    username = user    base = /home/%(username)    chdir = %(base)/%(project)    home = %(base)/Env/%(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 ???? systemd ????

???????????? Django ??????????????????????????????????? systemd ?????????????? uWSGI?

???????????????? / etc / systemd / system ???????????????????? uwsgi.service?

sudo nano /etc/systemd/system/uwsgi.service

?????????????????????????????????????

[Unit]    Description=uWSGI Emperor service

????????? [Service] ???????? ExecStartPre ??????????????????????? / run / uwsgi ????????????????? Nginx ??????????????????? -p ??? mkdir ? chown ?????????????????

??? ExecStart ????????????????? uwsgi ??????????????Emperor????????????? / etc / uwsgi / sites ??????????????????????????? systemd ???????????? uWSGI ???

[Service]    ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown user:nginx /run/uwsgi'    ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites    Restart=always    KillSignal=SIGQUIT    Type=notify    NotifyAccess=all

????????????? [Install] ?????????????????????????????????????????????????????????????????????????

[Install]    WantedBy=multi-user.target

????????????

??????????????????????? nginx ???????????????? nginx ?? uWSGI ???

????? Nginx ??????

???? uWSGI ????????????????? Nginx ?????????????? yum ??????

sudo yum install nginx

?? Nginx ???????????????????

http {    include /etc/nginx/conf.d/*.conf;    server {    }    server {    }    server {        listen 80 default_server;        server_name localhost;        . . .    }}

??????????? uWSGI ???????????????????????????

???????????????????????????????????????????

server {    listen 80;    server_name firstsite.com www.firstsite.com;}

????????? Nginx???????????????????????????????????????????????? Nginx ??????????????????

server {    listen 80;    server_name firstsite.com www.firstsite.com;    location = favicon.ico {        access_log off;        log_not_found off;    }    location /static/ {        root /home/user/firstsite;    }}

????????????????????????????? uWSGI?????? / etc / nginx / uwsgi_params ???? uwsgi ?????????? uWSGI ??????????

server {    listen 80;    server_name firstsite.com www.firstsite.com;    location = favicon.ico {        access_log off;        log_not_found off;    }    location /static/ {        root /home/user/firstsite;    }    location / {        include uwsgi_params;        uwsgi_pass unix:/run/uwsgi/firstsite.sock;    }}

??????????????????

??????????????????????????????????????????????????????????????????????????????

server {    listen 80;    server_name secondsite.com www.secondsite.com;    location = favicon.ico {        access_log off;        log_not_found off;    }    location /static/ {        root /home/user/secondsite;    }    location / {        include uwsgi_params;        uwsgi_pass unix:/run/uwsgi/secondsite.sock;    }}

???????????????

?? Nginx ????????????????

sudo nginx -t

???????????????????

??????????????????????????? Nginx ?????????????????????????????????????????????????????

???????? Nginx ????????????????????????????

sudo usermod -a -G user nginxchmod 710 /home/user

????????? Nginx ???? uWSGI ???

sudo systemctl start nginxsudo systemctl start uwsgi

???????????????????????????? Blond ?????????????

???????????????????????????

sudo systemctl enable nginxsudo systemctl enable uwsgi

转载地址:http://kqcfk.baihongyu.com/

你可能感兴趣的文章
nginx 常用配置记录
查看>>
nginx 开启ssl模块 [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx
查看>>
Nginx 我们必须知道的那些事
查看>>
Nginx 源码完全注释(11)ngx_spinlock
查看>>
Nginx 的 proxy_pass 使用简介
查看>>
Nginx 的 SSL 模块安装
查看>>
Nginx 的优化思路,并解析网站防盗链
查看>>
Nginx 的配置文件中的 keepalive 介绍
查看>>
Nginx 相关介绍(Nginx是什么?能干嘛?)
查看>>
Nginx 知识点一网打尽:动静分离、压缩、缓存、跨域、高可用、性能优化...
查看>>
nginx 禁止以ip形式访问服务器
查看>>
NGINX 端口负载均衡
查看>>
Nginx 结合 consul 实现动态负载均衡
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>
Nginx 负载均衡配置详解
查看>>
nginx 配置 单页面应用的解决方案
查看>>
nginx 配置dist 加上跨域配置
查看>>
nginx 配置https(一)—— 自签名证书
查看>>
nginx 配置~~~本身就是一个静态资源的服务器
查看>>