Centos7+python3+uwsgi+nginx+django

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


搭建服务器环境:

1.安装uwsgi:

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

2. 测试uWSGI:

2.1 编辑test.py, 内容如下:

(注意: 在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启动服务

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

2.3打开网页测试或者命令:

网页的话: 输入http://localhost:8000, 应该看到“Hello World”

命令的话:

[root@localhost ~]# curl localhost:8000

Hello World

[root@localhost ~]#

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


配置Django框架为生产环境的注意事项(DEBUG=False)

Issue description:

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

但是在生产环境,必须设置为:

DEBUG= False

ALLOWED_HOSTS = ['*'] #这样可以让所有来源的ip访问到后台

这样一来,不做任何其它设置的情况下, 打开网页的话,css/image 等文件显示不出来了

原因: DEBUG=False 下, django不处理静态文件。(需要其它配置, 并且官方也不建议)

官方解释: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结合jwplayer实现视频流媒体点播

你可能感兴趣的:(Centos7+python3+uwsgi+nginx+django)