日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用uWSGI部署django项目

發(fā)布時(shí)間:2023/11/30 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用uWSGI部署django项目 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先說(shuō)說(shuō)什么是uWSGI吧,他是實(shí)現(xiàn)了WSGI協(xié)議、uwsgi、http等協(xié)議的一個(gè)web服務(wù)器,那什么是WSGI呢?

WSGI是一種Web服務(wù)器網(wǎng)關(guān)接口。它是一個(gè)Web服務(wù)器(如nginx)與應(yīng)用服務(wù)器(如uWSGI服務(wù)器)通信的一種規(guī)范(協(xié)議)。

還有一種wsgi,uwsgi是一種線路協(xié)議而不是通信協(xié)議,在此常用于在uWSGI服務(wù)器與其他網(wǎng)絡(luò)服務(wù)器的數(shù)據(jù)通信。uwsgi協(xié)議是一個(gè)uWSGI服務(wù)器自有的協(xié)議,它用于定義傳輸信息的類(lèi)型(type of information)。

?

部署步驟:

1. 安裝uWSGI

(lofter) ? dj_test git:(master) pip install uwsgi Collecting uwsgi /home/wang/.virtualenvs/lofter/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.SNIMissingWarning /home/wang/.virtualenvs/lofter/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.InsecurePlatformWarningDownloading uwsgi-2.0.13.1.tar.gz (784kB)100% |████████████████████████████████| 788kB 1.4MB/s Building wheels for collected packages: uwsgiRunning setup.py bdist_wheel for uwsgi ... doneStored in directory: /home/wang/.cache/pip/wheels/01/e4/de/0b2bbeba234858bd780924d03031a4e817119aafb0cfc4c79e Successfully built uwsgi Installing collected packages: uwsgi Successfully installed uwsgi-2.0.13.1

以上命令是安裝目前穩(wěn)定版本的,也可以安裝LTS版本

# Or install LTS (long term support). $ pip install https://projects.unbit.it/downloads/uwsgi-lts.tar.gz

  

2. 安裝之后進(jìn)行簡(jiǎn)單的測(cè)試:

2.1 創(chuàng)建一個(gè)test.py文件:

# test.py def application(env, start_response):start_response('200 OK', [('Content-Type','text/html')])return [b"Hello World"] # python3#return ["Hello World"] # python2

2.2 啟動(dòng)uWSGI服務(wù)器:

uwsgi --http :8000 --wsgi-file test.py

意思是使用8000端口啟動(dòng)這個(gè)文件,效果如下:

 

(lofter) ? dj_test git:(master) uwsgi --http :8000 --wsgi-file test.py *** Starting uWSGI 2.0.12 (64bit) on [Mon May 23 21:15:56 2016] *** compiled with version: 4.8.4 on 08 April 2016 10:44:49 os: Linux-3.13.0-86-generic #130-Ubuntu SMP Mon Apr 18 18:27:15 UTC 2016 nodename: wang-N46VZ machine: x86_64 clock source: unix detected number of CPU cores: 8 current working directory: /home/wang/Workspace/Git/show-me-the-code/dj_test detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 62795 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on :8000 fd 4 spawned uWSGI http 1 (pid: 5539) uwsgi socket 0 bound to TCP address 127.0.0.1:47320 (port auto-assigned) fd 3 Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x21b8ff0 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72768 bytes (71 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x21b8ff0 pid: 5538 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 5538, cores: 1)

2.3 訪問(wèn) localhost:8000

顯示 hello world(linux截圖太麻煩了,見(jiàn)諒)

這就說(shuō)明uWSGI啟動(dòng)成功了~可以設(shè)置uWSGI啟動(dòng)django了

?

3. 使用uWSGI啟動(dòng)django項(xiàng)目

(lofter) ? dj_test git:(master) uwsgi --http :8000 --file dj_test/wsgi.py *** Starting uWSGI 2.0.12 (64bit) on [Mon May 23 21:19:35 2016] *** compiled with version: 4.8.4 on 08 April 2016 10:44:49 os: Linux-3.13.0-86-generic #130-Ubuntu SMP Mon Apr 18 18:27:15 UTC 2016 nodename: wang-N46VZ machine: x86_64 clock source: unix detected number of CPU cores: 8 current working directory: /home/wang/Workspace/Git/show-me-the-code/dj_test detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 62795 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on :8000 fd 4 spawned uWSGI http 1 (pid: 5649) uwsgi socket 0 bound to TCP address 127.0.0.1:60536 (port auto-assigned) fd 3 Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x2263ff0 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72768 bytes (71 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x2263ff0 pid: 5648 (default app) *** uWSGI is running in multiple interpreter mode ***

訪問(wèn)網(wǎng)址,就可以看見(jiàn)你的項(xiàng)目了~

常用命令:

uwsgi --chdir=/path/to/your/project \--module=mysite.wsgi:application \--env DJANGO_SETTINGS_MODULE=mysite.settings \--master --pidfile=/tmp/project-master.pid \--socket=127.0.0.1:49152 \ # can also be a file--processes=5 \ # number of worker processes--uid=1000 --gid=2000 \ # if root, uwsgi can drop privileges--harakiri=20 \ # respawn processes taking more than 20 seconds--max-requests=5000 \ # respawn processes after serving 5000 requests--vacuum \ # clear environment on exit--home=/path/to/virtual/env \ # optional path to a virtualenv--daemonize=/var/log/uwsgi/yourproject.log # background the process  

?

?

實(shí)際上到這里就算部署成功了,不過(guò)現(xiàn)實(shí)中一般使用nginx和uWSGI配合使用,使用nginx處理/static/以及/media/的請(qǐng)求,其他的交給uWSGI處理。

(下面基本是翻譯,而且還沒(méi)有翻譯完

1. 安裝nginx并配置nginx

sudo apt-get install nginx sudo /etc/init.d/nginx start # start nginx

配置文件(需要去看一下nginx簡(jiǎn)單配置)

# mysite_nginx.conf# the upstream component nginx needs to connect to upstream django {# server unix:///path/to/your/mysite/mysite.sock; # for a file socketserver 127.0.0.1:8001; # for a web port socket (we'll use this first) }# configuration of the server server {# the port your site will be served onlisten 8000;# the domain name it will serve forserver_name .example.com; # substitute your machine's IP address or FQDNcharset utf-8;# max upload sizeclient_max_body_size 75M; # adjust to taste# Django medialocation /media {alias /path/to/your/mysite/media; # your Django project's media files - amend as required}location /static {alias /path/to/your/mysite/static; # your Django project's static files - amend as required}# Finally, send all non-media requests to the Django server.location / {uwsgi_pass django;include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed} }

做個(gè)鏈接使得nginx可以訪問(wèn)到配置文件

sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/

2. 部署靜態(tài)文件

python manage.py collectstatic STATIC_ROOT一定要設(shè)置好了

3. 重啟nginx(第一次部署需要重啟,以后進(jìn)行了第二步之后只需要重啟uWSGI就可以了)

sudo /etc/init.d/nginx restart

4. 啟動(dòng)

uwsgi --socket :8001 --wsgi-file test.py

5. 添加uWSGI配置文件

# mysite_uwsgi.ini file [uwsgi]# Django-related settings # the base directory (full path) chdir = /path/to/your/project # Django's wsgi file module = project.wsgi # the virtualenv (full path) home = /path/to/virtualenv# process-related settings # master master = true # maximum number of worker processes processes = 10 # the socket (use the full path to be safe socket = /path/to/your/project/mysite.sock # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true

按照配置文件啟動(dòng)

uwsgi --ini mysite_uwsgi.ini # the --ini option is used to specify a file

6. 使用兩者共同拉起項(xiàng)目

uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=664

  

If that doesn’t work

Check your nginx error log(/var/log/nginx/error.log). If you see something like:

connect() to unix:///path/to/your/mysite/mysite.sock failed (13: Permission denied)

then probably you need to manage the permissions on the socket so that nginx is allowed to use it.

Try:

uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666 # (very permissive)

or:

uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=664 # (more sensible)

You may also have to add your user to nginx’s group (which is probably www-data), or vice-versa, so that nginx can read and write to your socket properly.

It’s worth keeping the output of the nginx log running in a terminal window so you can easily refer to it while troubleshooting.

?

參考:

http://baike.baidu.com/link?url=ClozvG5bxABaSkxztwURPZAOrySGwwBNMJEiPVOWfv7dPvJwEw_ZYPK3mUn0miC5_YNnHFG27tKvv6B3wktL1K

https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/uwsgi/

http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

轉(zhuǎn)載于:https://www.cnblogs.com/wswang/p/5521566.html

總結(jié)

以上是生活随笔為你收集整理的使用uWSGI部署django项目的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品国产亚洲av麻豆色欲 | 色欲久久久天天天综合网 | 超碰97人人射妻 | 久草资源在线观看 | 亚洲free性xxxx护士白浆 | 黄色69 | 国产三级网站 | 国产成人在线视频网站 | 女人的天堂网站 | 国产精品传媒麻豆hd | 亚洲免费黄色 | 嫩草研究院在线 | 本田岬av | 91人妻一区二区 | 日本三区视频 | 日韩精品免费一区 | 美女擦边视频 | 亚洲天堂影院在线观看 | 国产乱码av | 亚洲欧美日韩国产一区二区 | 夜夜嗨av | 国产精品伦| 亚洲系列在线观看 | 大香蕉精品一区 | 亚洲午夜网 | 肉丝美脚视频一区二区 | 日本美女视频 | 校园春色中文字幕 | 黄色性大片 | 国产草草 | 国产又粗又猛又爽又黄视频 | 91蜜臀精品国产自偷在线 | 巨胸喷奶水www久久久免费动漫 | k8经典成人理伦片 | 国产一区二区视频在线播放 | 好男人香蕉影院 | 久久久久综合 | 清纯唯美亚洲综合 | 中文字幕在线网站 | 日本一区二区三区精品视频 | 视频在线免费观看 | 日韩欧美高清在线视频 | 欧亚在线视频 | 日韩精品在线一区二区 | 亚洲我不卡 | 久久这里只有精品8 | 男男h黄动漫啪啪无遮挡软件 | 色香影视 | 久久机热 | 色呦呦一区 | 天堂av最新网址 | 伊人论坛| 成人免费网站www网站高清 | 亚洲无码国产精品 | 亚洲精品一二三四 | 精品国产av色一区二区深夜久久 | 色噜噜狠狠狠综合曰曰曰88av | 97夜色 | 国产小视频在线 | xxxxx在线| 免费视频91| 欧美乱码精品一区二区三区 | 欧美日本一二三区 | 亚洲av成人无码久久精品老人 | 嫩草影院久久 | 日本亲子乱子伦xxxx | 秘密基地在线观看完整版免费 | 国产 日韩 欧美 制服丝袜 | 依人成人网 | 亚洲第一二三区 | 性爱视频在线免费 | 久青草免费视频 | 蜜桃传媒一区二区亚洲av | 欧洲一级黄 | 丝袜 中出 制服 人妻 美腿 | 成人听书哪个软件好 | hd极品free性xxx护士 | 徐锦江一级淫片免费看 | 亚洲大逼 | 三级av毛片 | 亚洲av电影天堂男人的天堂 | 蜜臀aⅴ国产精品久久久国产老师 | 成人国产三级 | av免费在线观看网站 | cao死你| jizz欧美大全| 亚洲天堂美女 | 高h大肚孕期孕妇play | 国产性xxx| 国产做爰全过程免费视频 | 久热中文字幕 | 麻豆伊甸园 | 国产精品久久久久久久免费看 | 日韩精品第一页 | 天天草视频 | 成人国产精品久久久 | 一区二区成人免费视频 | 午夜在线一区二区 | 中文字幕日本人妻久久久免费 |