个人博客页面链接:http://www.shihao.online/(django搭建的个人博客,还在完善中)
安装Nginx
sudo apt-get install nginx #安装
启动Nginx
fnngj@ubuntu:~$ /etc/init.d/nginx start #启动
fnngj@ubuntu:~$ /etc/init.d/nginx stop #关闭
fnngj@ubuntu:~$ /etc/init.d/nginx restart #重启
安装uwsji
sudo python3 -m pip install uwsgi
测试uwsji
在Django项目下新建test.py文件,
# test.py
def 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.wsgi
blog为你的项目名。访问http://localhost:8001,项目正常。注意这时项目的静态文件是不会被加载的,需要用nginx做静态文件代理。
#在项目目录下创建uwsgi.ini文件, 代码如下
# myweb_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8000
# the base directory (full path)
chdir = /home/blog
# Django s wsgi file
module = myweb.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
待续