Nginx+uWSGI+Django+Python+ MySQL 搭建可靠的Python Web服务(2)

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

参考CentOS 6.4安装配置Nginx+Pcre+php-fpm 

注意编译的时候要加上参数:--with-cc-opt='-O3' --with-cpu-opt=opteron

[root@htuidc nginx-1.4.2]# ./configure --with-http_stub_status_module --prefix=/usr/local/nginx --with-cc-opt='-O3' --with-cpu-opt=opteron

四、安装MySql-Python

wget

tar zxvf MySQL-python-1.2.3.tar.gz

cd MySQL-python-1.2.3

python setup.py install

ImportError: No module named setuptools 解决方案 :

wget

tar zxvf setuptools-0.6c11.tar.gz

cd setuptools-0.6c11

python setup.py build

python setup.py install

/usr/bin/ld: cannot find -lpython2.7错误,解决方案 :

cd /usr/lib

ln -s /usr/local/python27/lib/libpython2.7.so libpython2.7.so

ll -a|grep python

lrwxrwxrwx. 1 root root 39 Oct 1 16:39 libpython2.7.so -> /usr/local/python27/lib/libpython2.7.so

drwxr-xr-x. 3 root root 4096 May 3 15:15 python2.6

出错:error: command 'gcc' failed with exit status 1

处理方法:

yum -y install mysql-devel

安装完成,到你的python安装目录下的site-packages目录里检查以下文件是否存在,如果存在即代表安装成功了

Linux:MySQL_python-1.2.3c1-py2.6-linux-i686.egg

测试方法

1)运行命令python进入python运行环境

2)输入以下python代码进行测试

import MySQLdb

test=MySQLdb.connect(db='mydb',host='localhost',user='root',passwd='p')

cur = test.cursor()

cur.execute('show databases;')

for data in cur.fetchall():

print data

五、安装Django

wget https://www.djangoproject.com/m/releases/1.5/Django-1.5.4.tar.gz

tar xzvf Django-1.5.4.tar.gz

cd Django-1.5.4

python setup.py install

测试Django安装

终端中输入 python,进入python交互模式,输入如下:

>>>import django

django.VERSION

正常情况会显示版本号码。

六、nginx配置

server {

listen 80; ## listen for ipv4; this line is default and implied

#listen [::]:80 default ipv6only=on; ## listen for ipv6

server_name blog.hysia.com;

access_log /var/log/nginx/blog.hysia.com-access.log ;

error_log /var/log/nginx/blog.hysia.com-error.log ;

location / {

uwsgi_pass 127.0.0.1:8630;

include uwsgi_params;

}

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/af21e42ed2be8598253f909cc4e2de87.html