在此文http://briteming.blogspot.co.uk/2013/12/linux-vpspythondjango-djangoselfblog.html,说过用gunicorn+nginx跑django项目。(演示站点:
http://yl-cname.brite.biz:81/),其实用gunicorn+apache也是可跑django项目的。
做法如下:
(youflog-0.3)as3:~/youflog-0.3/youflog# nohup ~/youflog-0.3/bin/gunicorn_django --workers=2 -b 127.0.0.1:36485 > /dev/null &
(注意:必须先进入django项目的文件夹,即含有manage.py文件的那个文件夹里,然后启动gunicorn.开启2个进程跑Django项目,使用nohup守护进程。)
mkdir /var/yl-cname.brite.biz/
cd /var/yl-cname.brite.biz/
nano .htaccess
( .htaccess的内容为:
我更宁愿用gunicorn+apache跑django项目,省得时不时看到nginx网站的那个讨厌的
“502 bad gateway"提示。
-------------------------------------
这段.htaccess的内容:
http://yl-cname.brite.biz:81/),其实用gunicorn+apache也是可跑django项目的。
做法如下:
(youflog-0.3)as3:~/youflog-0.3/youflog# nohup ~/youflog-0.3/bin/gunicorn_django --workers=2 -b 127.0.0.1:36485 > /dev/null &
(注意:必须先进入django项目的文件夹,即含有manage.py文件的那个文件夹里,然后启动gunicorn.开启2个进程跑Django项目,使用nohup守护进程。)
mkdir /var/yl-cname.brite.biz/
cd /var/yl-cname.brite.biz/
nano .htaccess
( .htaccess的内容为:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://localhost:36485/$1 [P]
然后在apache的配置文件里加一个virtualhost段:
<VirtualHost vps-ip:80>
ServerName yl-cname.brite.biz
DocumentRoot /var/yl-cname.brite.biz/
</VirtualHost>
ServerName yl-cname.brite.biz
DocumentRoot /var/yl-cname.brite.biz/
</VirtualHost>
然后重启apache,即可访问http://yl-cname.brite.biz/,它的内容跟
http://yl-cname.brite.biz:81/是一模一样的。
当然在你的apache server上,需启用proxy模块和proxy_http模块:
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_connect 我更宁愿用gunicorn+apache跑django项目,省得时不时看到nginx网站的那个讨厌的
“502 bad gateway"提示。
-------------------------------------
这段.htaccess的内容:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://somedomain.com/$1 [P]
很有用。
很有用。
请注意最后是 [P],而不是平时我们使用域名重定向的[R]。[P]代表的是proxy,而[R]是代表Redirect。
原始地址(被封的目标网址): http://briteming.appspot.com