RHEL6.1下nginx配置django服务器

RHEL6.1下nginx配置django服务器

1.Nginx安装

1.1下载

1.2安装

$tarzxvfnginx-1.0.11.tar.gz

$cdnginx-1.0.11

$./configure--prefix=/opt/apps/nginx-1.0.11

$make

$makeinstall

1.3配置

$vim/opt/apps/nginx-1.0.11/conf/nginx.conf

修改location为:

location/{

roothtml;

indexindex.htmlindex.htm;

fastcgi_pass127.0.0.1:3000;

fastcgi_paramPATH_INFO$fastcgi_script_name;

fastcgi_paramREQUEST_METHOD$request_method;

fastcgi_paramQUERY_STRING$query_string;

fastcgi_paramCONTENT_TYPE$content_type;

fastcgi_paramCONTENT_LENGTH$content_length;

fastcgi_pass_headerAuthorization;

fastcgi_intercept_errorsoff;

}

添加:

#添加djangoadmincssjs的支持,否则django下的admin显示不了css,js

location/admin-media/{

alias/usr/lib/python2.6/site-packages/django/contrib/admin/media/;

}

$vim/home/tony/dj_my_pro/today_go/settings.py

ADMIN_MEDIA_PREFIX修改为:

ADMIN_MEDIA_PREFIX='/admin-media/'#同nginx.conf配置的location中admin-media对应

2.Flup安装(randomPythonWSGIstuff)

2.1下载

2.2安装:

$sudoeasy_installflup-1.0.2-py2.6.egg

3.Django启动

$cd/home/tony/dj_my_pro/today_go

$pythonmanage.pyrunfcgimethod=preforkhost=127.0.0.1port=3000

(这里host和port是同nginx.conf中fastcgi_pass中配置相对应的)

4.Nginx启动

$sudo/opt/apps/nginx-1.0.11/sbin/nginx-c/opt/apps/nginx-1.0.11/conf/nginx.conf

$sudoln-s/opt/apps/nginx-1.0.11/sbin/nginx/usr/bin/nginx

5.访问

http://localhost

http://localhost/admin

6.重启,关闭

6.1nginx关闭,启动

$sudonginx-h#会发现-s可以满足重启之类的要求,默认就是用的conf/nginx.conf配置

$sudonginx-s[stop,quit,reopen,reload]

或者通过kill方法

6.2django重新启动

通过kill杀掉,还没发现比较好的方法

----------------------------------------------------------------------------------------------

安装过程中可能出现的错误:

1../configure:error:theHTTPrewritemodulerequiresthePCRElibrary.

解决方案:

$sudoyuminstallpcre-devel

相关推荐