Centos7+python3+uwsgi+nginx+django

前提:Centos7+python3+nginx+django are already installed.


搭建服務(wù)器環(huán)境:

1.安裝uwsgi:

[root@localhost ~]# pip3.6 install uwsgi?

2. 測(cè)試uWSGI:

2.1 編輯test.py, 內(nèi)容如下:

(注意: 在python3中,return [b"Hello World\n"])

[root@localhost ~]# cat test.py

def application(env, start_response):

? ? start_response('200 OK', [('Content-Type','text/html')])

? ? return [b"Hello World\n"]

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

[root@localhost ]# uwsgi --http 0.0.0.0:8000 --wsgi-file test.py

2.3打開網(wǎng)頁測(cè)試或者命令:

網(wǎng)頁的話: 輸入http://localhost:8000, 應(yīng)該看到“Hello World”

命令的話:

[root@localhost ~]# curl localhost:8000

Hello World

[root@localhost ~]#

note:如果端口被占用,可以: lsof-i:8000 ? +kill -9 pid


配置Django框架為生產(chǎn)環(huán)境的注意事項(xiàng)(DEBUG=False)

Issue description:

In django's development mode (DEBUG=True), so django can handle static files correctly.

但是在生產(chǎn)環(huán)境,必須設(shè)置為:

DEBUG= False

ALLOWED_HOSTS = ['*'] #這樣可以讓所有來源的ip訪問到后臺(tái)

這樣一來,不做任何其它設(shè)置的情況下, 打開網(wǎng)頁的話,css/image 等文件顯示不出來了

原因: DEBUG=False 下, django不處理靜態(tài)文件。(需要其它配置, 并且官方也不建議)

官方解釋:https://docs.djangoproject.com/en/1.9/howto/static-files/deployment/

“This is not suitable for production use!”

“Most larger Django sites use a separate Web server – i.e., one that’s not also running Django – for serving static files. This server often runs a different type of web server – faster but less full-featured. Some common choices are:?? nginx or apache”





http://blog.csdn.net/c465869935/article/details/53242126


https://www.cnblogs.com/fnng/p/5268633.html

http://blog.csdn.net/c465869935/article/details/53242126

https://www.imooc.com/article/19452: nginx結(jié)合jwplayer實(shí)現(xiàn)視頻流媒體點(diǎn)播

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容