python?配置uwsgi?啟動(dòng)Django框架的詳細(xì)教程
1. 安裝pip3
yum install python34-pip
2. 安裝python34devel
yum install python34-devel
3. pip3 安裝依賴(lài)
pip3 install -r requirements
4. 安裝uwsgi
pip3 install uwsgi
編寫(xiě)test.py測(cè)試uwsgi
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3 #return ["Hello World"] # python2
uwsgi --http :9090 --wsgi-file test.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
5. uwsgi 配置 (simp)
編寫(xiě)uwsgi.ini,以wsgi方式啟動(dòng)uwsgi,此時(shí)無(wú)法通過(guò)web訪(fǎng)問(wèn)的方式測(cè)試是否啟動(dòng),
#uwsgi配置文件 [uwsgi] # 轉(zhuǎn)發(fā)給nginx 的端口 socker=:9000 #http=:9000 # 項(xiàng)目目錄 master=true chdir = /home/oper/simp/Weekreport wsgi-file = Weekreport/wsgi.py # 進(jìn)程數(shù) workers = 5 processes = 5 threads = 2 buffer-size = 130000 # 設(shè)置日志目錄 daemonize = /home/oper/simp/Weekreport/log/uwsgi.log stats=%(chdir)/uwsgi/uwsgi.status pidfile=%(chdir)/uwsgi/uwsgi.pid
uwsgi啟動(dòng)的linux shell命令,項(xiàng)目在/home/oper/simp/Weekreport下
# 啟動(dòng) uwsgi --ini /home/oper/Weekreport/uwsgi.ini # 停止 uwsgi --stop /home/oper/Weekreport/uwsgi/uwsgi.pid # 啟動(dòng) uwsgi --ini /home/oper/Weekreport/uwsgi.ini # 停止 uwsgi --stop /home/oper/Weekreport/uwsgi/uwsgi.pid
如控制臺(tái)出現(xiàn)以下提示,八成是成功了
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x12b9fa0 pid: 2402 (default app) mountpoint already configured. skip. uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 2402, cores: 1)
啟動(dòng)uwsgi服務(wù),設(shè)置開(kāi)機(jī)啟動(dòng)
systemctl start uwsgi systemctl enable uwsgi
6. nginx的配置
6.1 uwsgi 后端nginx 配置
在/etc/nginx/conf.d下新建一個(gè)uwsgi.conf ```bash # mysite_nginx.conf # configuration of the server server { # the port your site will be served on listen 80 default_server; server_name localhost; charset utf-8; access_log /applog/nginx/logs/access.log main; proxy_set_header Host $host; proxy_set_header X-Real_ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_read_timeout 300 location / { include uwsgi_params; uwsgi_pass 28.106.81.81:9000 } location /api/{ proxy_pass http://28.106.81.81:8080/; } location /collection/{ proxy_pass http://localhost:9999/; } location /api-collection/{ proxy_pass http://localhost/collection/api/; } }
6.2 nginx 前端nginx 配置
在/etc/nginx/conf.d下新建一個(gè)uwsgi.conf
# mysite_nginx.conf # configuration of the server server { # the port your site will be served on listen 80 default_server; # the domain name it will serve for server_name simp; charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location / { proxy_pass http://28.106.81.81; # 此處是uwsgi 對(duì)應(yīng)的后端Nginx # uwsgi_pass localhost:5000; # 此處與uwsgi.ini的socket是對(duì)應(yīng)的 } location /static { alias /root/hujun_app/ocv-simp/Weekreport/static; # your Django project's static files - amend as required } location /api-collection/{ proxy_pass http://localhost/collection/api/; } location /collection/{ proxy_pass http://localhost:9999/; } }
到此這篇關(guān)于python 配置uwsgi 啟動(dòng)Django框架的文章就介紹到這了,更多相關(guān)python uwsgi 配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python?配置uwsgi?啟動(dòng)Django框架的詳細(xì)教程
- django生產(chǎn)環(huán)境搭建(uWSGI+django+nginx+python+MySQL)
- VPS CENTOS 上配置python,mysql,nginx,uwsgi,django的方法詳解
- 使用Nginx+uWsgi實(shí)現(xiàn)Python的Django框架站點(diǎn)動(dòng)靜分離
- 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
- 在Linux系統(tǒng)上通過(guò)uWSGI配置Nginx+Python環(huán)境的教程
- 詳解使用Nginx和uWSGI配置Python的web項(xiàng)目的方法
相關(guān)文章
深度學(xué)習(xí)Tensorflow2.8實(shí)現(xiàn)GRU文本生成任務(wù)詳解
這篇文章主要為大家介紹了深度學(xué)習(xí)Tensorflow?2.8?實(shí)現(xiàn)?GRU?文本生成任務(wù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Python PyQt4實(shí)現(xiàn)QQ抽屜效果
這篇文章主要為大家詳細(xì)介紹了Python PyQt4實(shí)現(xiàn)QQ抽屜效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04解決python和pycharm安裝gmpy2 出現(xiàn)ERROR的問(wèn)題
這篇文章主要介紹了python和pycharm安裝gmpy2 出現(xiàn)ERROR的解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08詳解Python開(kāi)發(fā)中如何使用Hook技巧
這篇文章主要介紹了詳解Python開(kāi)發(fā)中如何使用Hook技巧,詳細(xì)的介紹了Python Hook的用法和示例,有興趣的可以了解一下2017-11-11如何利用?Python?繪制動(dòng)態(tài)可視化圖表
這篇文章主要介紹了如何利用?Python?繪制動(dòng)態(tài)可視化圖表,主要介紹介紹如何進(jìn)行保存gif格式的文件。那么我們就開(kāi)始進(jìn)入主題,來(lái)談一下Python當(dāng)中的gif模塊,需要的朋友可以參考一下2022-02-02Pandas時(shí)間序列:重采樣及頻率轉(zhuǎn)換方式
今天小編就為大家分享一篇Pandas時(shí)間序列:重采樣及頻率轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12python代碼如何調(diào)出cmd命令行窗口并在cmd窗口中執(zhí)行指定的命令
這篇文章主要介紹了python代碼如何調(diào)出cmd命令行窗口并在cmd窗口中執(zhí)行指定的命令問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02