linux下通过Nginx部署django项目

来源:互联网 发布:我国农产品出口数据 编辑:程序博客网 时间:2024/05/21 23:34
安装Nginxsudo apt-get install nginx  #安装
启动Nginxfnngj@ubuntu:~$ /etc/init.d/nginx start  #启动fnngj@ubuntu:~$ /etc/init.d/nginx stop  #关闭fnngj@ubuntu:~$ /etc/init.d/nginx restart  #重启
安装uwsjisudo python3 -m pip install uwsgi
测试uwsji在Django项目下新建test.py文件,# test.pydef application(env, start_response):    start_response('200 OK', [('Content-Type','text/html')])    return ["Hello World"] # python2    #return [b"Hello World"] # python3然后执行下列命令uwsgi --http :8001 --plugin python --wsgi-file test.py然后打开ttp://localhost:8001看是否运行正常
然后链接Django和uwsgi,实现简单的web服务器,到Django项目目录下执行shell:uwsgi --http :8001 --plugin python --module blog.wsgiblog为你的项目名。访问http://localhost:8001,项目正常。注意这时项目的静态文件是不会被加载的,需要用nginx做静态文件代理。
#在项目目录下创建uwsgi.ini文件, 代码如下# myweb_uwsgi.ini file[uwsgi]# Django-related settingssocket = :8000# the base directory (full path)chdir           = /home/blog# Django s wsgi filemodule          = myweb.wsgi# process-related settings# mastermaster          = true# maximum number of worker processesprocesses       = 4# ... with appropriate permissions - may be needed# chmod-socket    = 664# clear environment on exitvacuum          = true

待续

原创粉丝点击