前提: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)播