ngnix+uwsgi+django+python+mysql環境部署

來源:互聯網
上載者:User

標籤:quit   create   path   emd   run   tar   資料庫   you   manage   

django
一個python的web架構
flask和django

uwsgi
一個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 = 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測試:瀏覽器地址欄:http://xiangmu.buy360.xyz

ngnix+uwsgi+django+python+mysql環境部署

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.