CentOS6.5

xiaoxiao2021-02-28  132

本文章为各位介绍一篇关于CentOS6.5_64下 nginx+uwsgi+Python +多站点环境搭建 python web django 框架的例子。

作为一个严谨(其实就是有强迫症)的程序,为了确保正确安装这个东西,费了我好长时间。首先,查找包里的readme,发现没有安装提示。各种被墙,辗转良久,才查看到uwsgi的官方文档说明: http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html 

所以,也就有了本文。

言归正传,下面是 uwsgi 的两种安装方式:

方式一:

采用源码(source tarball)安装uwsgi。

可以去pypi,搜索uwsgi下载:

https://pypi.Python.org/pypi/uWSGI/ 

安装命令如下:

tar xvzf uwsgi-2.0.9.tar.gz

cd uwsgi-2.0.9

make

方式二:

使用pip安装uwsgi(这也是django1.7文档里推荐的方式):

pip install uwsgi

注:下图为官网的安装说明截图:

■ 配置uwsgi:

首先要明确的是,如果你喜欢用命令行的方式(如shell)敲命令,那可以省去任何配置。

但是,绝大多数人,还是不愿意记那么长的命令,反复敲的。所以uwsgi里,就给大家提供了多种配置,省去你启动时候,需要敲一长串命令的过程。

uwsgi 有多种配置可用:

1,ini ,

2,xml ,

3,json

4,yaml。

从uwsgi的官方文档来看,貌似(我个人的理解)推荐用ini方式,所以下面的配置也都是基于ini的。

● ini 格式说明:

1,ini配置为 key=value 形式

2,在ini配置文件里,#号为注释,

3,布尔值为 true  false 

4,在命令行里,uwsgi myconf.ini 等价于 uwsgi --ini myconf.ini 

●  ini 配置示例:

[python]  view plain  copy   [uwsgi]   socket = 127.0.0.1:8000   workers = 4  

■ uwsgi 选项说明:

● 选项的格式:

1,命令行参数格式:--<option> 

2,配置格式(以ini为例):option = xxxx 

● 常用选项:

socket : 地址和端口号,例如:socket = 127.0.0.1:50000

processes : 开启的进程数量

workers : 开启的进程数量,等同于processes(官网的说法是spawn the specified number of  workers / processes)

chdir : 指定运行目录(chdir to specified directory before apps loading)

wsgi-file : 载入wsgi-file(load .wsgi file)

stats : 在指定的地址上,开启状态服务(enable the stats server on the specified address)

threads : 运行线程。由于GIL的存在,我觉得这个真心没啥用。(run each worker in prethreaded mode with the specified number of threads)

master : 允许主进程存在(enable master process)

daemonize : 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)。实际上最常用的,还是把运行记录输出到一个本地文件上。

log-maxsize :以固定的文件大小(单位KB),切割日志文件。 例如:log-maxsize = 50000000  就是50M一个日志文件。 

pidfile : 指定pid文件的位置,记录主进程的pid号。

vacuum : 当服务器退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)

disable-logging : 不记录请求信息的日志。只记录错误以及uWSGI内部消息到日志中。如果不开启这项,那么你的日志中会大量出现这种记录:

[pid: 347|app: 0|req: 106/367] 117.116.122.172 () {52 vars in 961 bytes} [Thu Jul  7 19:20:56 2016] POST /post => generated 65 bytes in 6 msecs (HTTP/1.1 200) 2 headers in 88 bytes (1 switches on core 0)

● 其他选项说明:

其他选项,具体可以通过 --help 选项来查看:

uwsgi --help

注:下图为官网的 django  ini 配置说明截图:

====================================================================================

■ 下面是一些比较实用的配置:

[uwsgi] socket = 127.0.0.1:50000 chdir = /home/httpServer/ wsgi-file = httpServer/wsgi.py processes = 4 stats = 127.0.0.1:9090 daemonize = /home/log/httpServer.log pidfile = /tmp/uwsgi.pid vacuum = true log-maxsize = 50000000

disable-logging = true

■ 参考:

A,《官方文档》:

http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html

B,《uWSGI参考资料》:

http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html

 安装uwsgi:

安装uwsgi,请看我上一篇文章:《uWSGI的安装与配置(官网摘录)》。

■ 配置uwsgi:

由于我们使用django,所以配置一个能跟django进行关联的ini,首先我们先看一下Django1.7官方文档给出的配置:

但是又看了一下uwsgi 的官方文档,发现上面的配置有点旧,新的配置做了简化,

所以,根据Django和uWSGI 的文档,我重新整理了一个新的配置,如下:

[plain]  view plain  copy [uwsgi]   socket = 127.0.0.1:50000   chdir = /home/wwwroot/myweb/   wsgi-file = myweb/wsgi.py   processes = 2   stats = 192.168.1.18:9090   daemonize = /var/log/uwsgi/yourproject.log   vacuum = true   ● 解释一下常用选项:

socket : 地址和端口号,例如:socket = 127.0.0.1:50000

processes : 开启的进程数量

workers : 开启的进程数量,等同于processes(官网的说法是spawn the specified number of workers / processes)

chdir : 指定运行目录(chdir to specified directory before apps loading)

wsgi-file : 载入wsgi-file(load .wsgi file)

stats : 在指定的地址上,开启状态服务。注意,这里尽量用非127.0.0.1的IP。(enable the stats server on the specified address)

threads : 运行线程。由于GIL的存在,我觉得这个真心没啥用。(run each worker in prethreaded mode with the specified number of threads)

master : 允许主进程存在(enable master process)

daemonize : 使进程在后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)

vacuum  : 当服务器退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)

■ 启动uwsgi:

把上面编辑好的 ini 文件,保存为【 uwsgi_conf.ini 】,注意为ANSI格式,如果是UTF-8,则报错。

理论上可以把这个ini文件,放到服务器任意位置。但还是推荐放到项目下,然后运行:

uwsgi uwsgi_conf.ini 

■ Nginx配置:

nginx安装不在叙述,这里主要讲如何更改nginx.conf:

location / {     include uwsgi_params;     uwsgi_pass 127.0.0.1:50000; }

■ 重启Nginx:

重启nginx,再次访问你的项目,一切OK! 

■ 参考:

A,《你应该使用 Nginx + UWSGI》: (本文的主要参考,放弃使用uwsgi自带的负载均衡,由此而来)

http://www.linuxidc.com/Linux/2013-07/87286.htm

B,《uwsgi其二》:

http://www.nowamagic.NET/academy/detail/1330331

C,《五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(下) 》:

http://django-china.cn/topic/124/

D,《How to use Django with uWSGI》:(Django官网文档,本文的次要参考)

https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/uwsgi/

nginx+uwsgi+Python环境介绍: 系统:CentOS6.5_64_mini nginx版本:nginx-1.6.0 python版本:Python2.7.8  

uwsgi -s 127.0.0.1:9001 --wsgi-file /home/wwwroot/myweb/manage.py 第一部分系统设置 1:查看系统内核 #  uname -r 2.6.32-431.el6.x86_64

2:更新内核 #  yum -y install kernel

3:重启系统 #  reboot

4:重启后查看是否启用新内核 #  uname -r 2.6.32-431.20.5.el6.x86_64

5:可以删除老内核节约空间呵呵 #  rpm -q kernel kernel-2.6.32-431.el6.x86_64 kernel-2.6.32-431.20.5.el6.x86_64 #  rpm -e kernel-2.6.32-431.el6.x86_64

6:删除mysql #  rpm -qa|grep mysql #  rpm -e --allmatches --node ps mysql-libs-5.1.71-1.el6.x86_64

第二部分安装安装nginx 1:安装Nginx所需的库: #  yum -y install gcc gcc-c++ openssl openssl-devel wget   2.创建/main/soft文件夹 #  mkdir /yunwei8/soft #  cd /yunwei8/soft   3:下载所需的安装包至soft文件夹下 #  wget http://down.yunwei8.com/soft/linux/distribute-0.6.49.tar.gz #  wget http://down.yunwei8.com/soft/linux/nginx-1.6.0.tar.gz #  wget http://down.yunwei8.com/soft/linux/pcre-8.35.tar.gz #  wget http://down.yunwei8.com/soft/linux/Python-2.7.8.tar.gz  

4:安装Nginx所需的pcre库 解压并安装 #  tar zxvf pcre-8.35.tar.gz #  cd pcre-8.35/ #  ./configure #  make && make install #  cd ../    5:创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限  #  /usr/sbin/groupadd www #  /usr/sbin/useradd -s /sbin/nologin -M -g www www #  mkdir -p /yunwei8/web/www #  chmod 777 /yunwei8/web/www #  chown -R www:www /yunwei8/web/www #  chmod g+s /yunwei8/web/www #  mkdir -p /yunwei8/web/logs #  chmod +w /yunwei8/web/logs #  chown -R www:www /home/wwwroot/myweb

 chmod -R  775 /home/wwwroot/myweb

  6:安装nginx 解压并安装  #  cd /yunwei8/soft #  tar zxvf nginx-1.6.0.tar.gz #  cd nginx-1.6.0 #  ./configure --user=www --group=www --prefix=/yunwei8/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-pcre=../pcre-8.35 --with-pcre-jit #  make && make install

7:修改 nginx.conf配置文件 #  vi /yunwei8/server/nginx/conf/nginx.conf

修改前面几行为: user www www; worker_processes 8; error_log  /yunwei8/web/logs/nginx_error.log  crit; pid logs/nginx.pid; events{   use epoll;   worker_connections 65535; }

测试  #  /yunwei8/server/nginx/sbin/nginx -t   如果显示下面信息,即表示配置没问题 nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx/conf/nginx.conf test is successful   输入代码运行nginx服务  #  /yunwei8/server/nginx/sbin/nginx   查看nginx进程  #  ps aux|grep [n]ginx  root     10603  0.0  0.1  42996  1128 ?        Ss   04:06   0:00 nginx: master process /yunwei8/server/nginx/sbin/nginx www      10604  0.2  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10605  0.2  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10606  0.1  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10607  0.3  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10608  0.2  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10609  0.2  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10610  0.2  2.8  70132 28512 ?        S    04:06   0:00 nginx: worker process            www      10611  0.2  2.8  70132 28496 ?        S    04:06   0:00 nginx: worker process  显以类似上面的信息,即表示nginx已经启动   8:编写nginx 启动服务  #  vi /etc/init.d/nginx   输入以下代码并保存 #!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig:   - 85 15  # description:  Nginx is an HTTP(S) server, HTTP(S) reverse  #               proxy and IMAP/POP3 proxy server # processname: nginx # config:      /yunwei8/server/nginx/conf/nginx.conf # pidfile:     /yunwei8/server/nginx/logs/nginx.pid   # Source function library. . /etc/rc.d/init.d/functions   # Source networking configuration. . /etc/sysconfig/network   # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0   nginx="/yunwei8/server/nginx/sbin/nginx" prog=$(basename $nginx)   NGINX_CONF_FILE="/yunwei8/server/nginx/conf/nginx.conf"   lockfile=/var/lock/subsys/nginx   start() {     [ -x $nginx ] || exit 5     [ -f $NGINX_CONF_FILE ] || exit 6     echo -n $"Starting $prog: "     daemon $nginx -c $NGINX_CONF_FILE     retval=$?     echo     [ $retval -eq 0 ] && touch $lockfile     return $retval }   stop() {     echo -n $"Stopping $prog: "     killproc $prog -QUIT     retval=$?     echo     [ $retval -eq 0 ] && rm -f $lockfile     return $retval }   restart() {     configtest || return $?     stop     start }   reload() {     configtest || return $?     echo -n $"Reloading $prog: "     killproc $nginx -HUP     RETVAL=$?     echo }   configtest() {   $nginx -t -c $NGINX_CONF_FILE }   rh_status() {     status $prog }   rh_status_q() {     rh_status >/dev/null 2>&1 }   case "$1" in     start)         rh_status_q && exit 0         $1         ;;     stop)         rh_status_q || exit 0         $1         ;;     restart|configtest)         $1         ;;     reload)         rh_status_q || exit 7         $1         ;;     status)         rh_status         ;;     *)         echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"         exit 2 esac  

保存后,设置权限并添加到启动服务列表中  #  chmod 755 /etc/init.d/nginx #  chkconfig --add nginx #  chkconfig --level 345 nginx on #  service nginx start   测试脚本 #  service nginx restart

9:防火墙设置 端口开放 #  /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   然后保存: #  /etc/rc.d/init.d/iptables save

第三部分安装Python及相应环境 1:安装Python2.7.8所需要的库  #  yum -y groupinstall "Development tools" #  yum -y install zlib-devel bzip2-devel pcre-devel ncurses-devel sqlite-devel readline-devel tk-devel

2:安装Python2.7.8 #  cd /yunwei8/soft #  xz -d Python-2.7.8.tar.xz #  tar xvf Python-2.7.8.tar #  cd Python-2.7.8 #  ./configure --prefix=/usr/local #  make && make altinstall

3:安装完毕后可是使用如下命令进入python2.7的环境 #  python2.7   退出指令有点特别,如下 #  exit()

4:安装Python包管理 4.1:安装distribute-0.6.49 #  cd /yunwei8/soft/ #  tar zxvf distribute-0.6.49.tar.gz #  cd distribute-0.6.49 #  python2.7 setup.py install #  easy_install --version

4.2:安装pip包,安装pip的好处是可以pip list、pip uninstall管理Python包,easy_install没有这个功能,只有uninstall #  easy_install pip #  pip --version

5:安装uwsgi 5.1:安装uwsgi #  pip install uwsgi   5.2:增加软连接防止报错 #  ln -s /usr/local/lib/libpcre.so.1 /lib64/   5.3查看版本 #  uwsgi --version   5.4:测试uwsgi是否正常 #  cd /yunwei8/web/www/ #  vi yunwei8.py

复制如下代码保存并退出 def application(env, start_response):   start_response('200 OK', [('Content-Type','text/html')])   return "Hello World"   赋予相应权限 #  chmod 755 yunwei8.py   关闭防火墙 #  service iptables stop   启动uwsgi #  uwsgi --http :8001 --wsgi-file yunwei8.py   在浏览器内输入:http://你的IP地址:8001,看是否有“Hello World”输出,若没有输出,请检查你的安装过程   6:安装django 6.1:安装django #  pip install django   6.2:测试django是否正常运行 #  cd /yunwei8/web/www #  django-admin.py startproject test1 #  cd test1 #  python2.7 manage.py runserver 0.0.0.0:8002   在浏览器内输入:http://你的IP地址:8002 It worked! Congratulations on your first Django-powered page.

7:配置uwsgi 7.1uwsgi支持ini、xml等多种配置方式,但个人感觉ini更方便: 在/ect/目录下新建uwsgi9090.ini,添加如下配置: #  vi /etc/uwsgi9090.ini [uwsgi] socket = 127.0.0.1:9090 master = true                                      #主进程 vhost = true                                        #多站模式 no-stie = true                                      #多站模式时不设置入口模块和文件 workers = 2                                        #子进程数 reload-mercy = 10      vacuum = true                                    #退出、重启时清理文件 max- request s = 1000    limit-as = 512 buffer-sizi = 30000 pidfile = /var/run/uwsgi9090.pid            #pid文件,用于下面的脚本启动、停止该进程 daemonize = /home/wwwroot/myweb/uwsgi9090.log  /usr/sbin/uwsgi 7.2设置uwsgi开机启动,在/ect/init.d/目录下新建uwsgi9090文件,并复制如下内容: #  vi /etc/init.d/uwsgi9090 #! /bin/sh # chkconfig: 2345 55 25 # Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and # run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your # distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'   ### BEGIN INIT INFO # Provides:          uwsgi # Required-Start:    $all # Required-Stop:     $all # Default-Start:     2 3 4 5 # Default-Stop:      0 1 6 # Short-Description: starts the uwsgi web server # Description:       starts uwsgi using start-stop-daemon ### END INIT INFO   # Author:   licess # website:  http://lnmp.org   PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="uwsgi daemon" NAME=uwsgi9090 DAEMON=/usr/bin/uwsgi CONFIGFILE=/etc/$NAME.ini PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME   set -e [ -x "$DAEMON" ] || exit 0   do_start() {     $DAEMON $CONFIGFILE || echo -n "uwsgi already running" }   do_stop() {     $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"     rm -f $PIDFILE     echo "$DAEMON STOPED." }   do_reload() {     $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload" }   do_status() {     ps aux|grep $DAEMON }   case "$1" in  status)     echo -en "Status $NAME: n"     do_status  ;;  start)     echo -en "Starting $NAME: n"     do_start  ;;  stop)     echo -en "Stopping $NAME: n"     do_stop  ;;  reload|graceful)     echo -en "Reloading $NAME: n"     do_reload  ;;  *)     echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2     exit 3  ;; esac   exit 0  

7.3添加服务并设置开机启动 #  chmod 755 /etc/init.d/uwsgi9090 #  chkconfig --add uwsgi9090  #  chkconfig uwsgi9090 on

8:配置nginx #  rm -rf /yunwei8/server/nginx/conf/nginx.conf #  vi /yunwei8/server/nginx/conf/nginx.conf user  www www; worker_processes  8; error_log  /yunwei8/web/logs/nginx_error.log  crit; pid        logs/nginx.pid; events {     use epoll;     worker_connections  65535; } http {     include        mime.types;     default_type  application/octet-stream;     server_names_hash_bucket_size 128;     client_header_buffer_size 32k;     large_client_header_buffers 4 32k;     client_max_body_size 8m;     sendfile        on;     tcp_nopush     on;     keepalive_timeout  60;          tcp_nodelay on;     fastcgi_connect_timeout 300;     fastcgi_send_timeout 300;     fastcgi_read_timeout 300;     fastcgi_buffer_size 64k;     fastcgi_buffers 4 64k;     fastcgi_busy_buffers_size 128k;     fastcgi_temp_file_write_size 128k;     gzip on;     gzip_min_length  1k;     gzip_buffers     4 16k;     gzip_http_version 1.0;     gzip_comp_level 2;     gzip_types       text/plain application/x- javascript text/css application/xml;     gzip_vary on; server {         listen       80;         server_name  localhost;                  location / {                         include  uwsgi_params;             uwsgi_pass  127.0.0.1:9090;                                              #必须和uwsgi中的设置一致             uwsgi_param UWSGI_SCRIPT test1.wsgi;                            #入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录             uwsgi_param UWSGI_CHDIR /yunwei8/web/www/test1;       #项目根目录             index  index.html index.htm;             client_max_body_size 35m;         }      error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }     } }

9:测试启动uwsgi并重启nginx #  service uwsgi9090 start #  service nginx restart

10:开启防火墙 #  service iptables start

11:访问测试 在浏览器内输入:http://你的IP地址 It worked! Congratulations on your first Django-powered page.

12:多站配置 我采用运行多个uwsgi服务的方法来实现多个站点 12.1配置uwsgi 在/ect/目录下新建uwsgi9091.ini #  vi /etc/uwsgi9091.ini [uwsgi] socket = 127.0.0.1:9091 master = true vhost = true no-stie = true workers = 2 reload-mercy = 10      vacuum = true max-requests = 1000    limit-as = 512 buffer-sizi = 30000 pidfile = /var/run/uwsgi9091.pid daemonize = /yunwei8/web/logs/uwsgi9091.log   12.2设置uwsgi开机启动,在/ect/init.d/目录下新建uwsgi9091文件,并复制如下内容: #  vi /etc/init.d/uwsgi9091 #! /bin/sh # chkconfig: 2345 55 25 # Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and # run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your # distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'   ### BEGIN INIT INFO # Provides:          uwsgi # Required-Start:    $all # Required-Stop:     $all # Default-Start:     2 3 4 5 # Default-Stop:      0 1 6 # Short-Description: starts the uwsgi web server # Description:       starts uwsgi using start-stop-daemon ### END INIT INFO   # Author:   licess # website:  http://lnmp.org   PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="uwsgi daemon" NAME=uwsgi9091 DAEMON=/usr/local/bin/uwsgi CONFIGFILE=/etc/$NAME.ini PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME   set -e [ -x "$DAEMON" ] || exit 0   do_start() {     $DAEMON $CONFIGFILE || echo -n "uwsgi already running" }   do_stop() {     $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"     rm -f $PIDFILE     echo "$DAEMON STOPED." }   do_reload() {     $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload" }   do_status() {     ps aux|grep $DAEMON }   case "$1" in  status)     echo -en "Status $NAME: n"     do_status  ;;  start)     echo -en "Starting $NAME: n"     do_start  ;;  stop)     echo -en "Stopping $NAME: n"     do_stop  ;;  reload|graceful)     echo -en "Reloading $NAME: n"     do_reload  ;;  *)     echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2     exit 3  ;; esac   exit 0  

12.3添加服务并设置开机启动 #  chmod 755 /etc/init.d/uwsgi9091 #  chkconfig --add uwsgi9091  #  chkconfig uwsgi9091 on   12.4使用django增加一个test2 #  cd /yunwei8/web/www #  django-admin.py startproject test2   12.5然后修改nginx的配置文件为: #  rm -rf /yunwei8/server/nginx/conf/nginx.conf #  vi /yunwei8/server/nginx/conf/nginx.conf user  www www; worker_processes  8; error_log  /yunwei8/web/logs/nginx_error.log  crit; pid        logs/nginx.pid; events {     use epoll;     worker_connections  65535; } http {     include       mime.types;     default_type  application/octet-stream;     server_names_hash_bucket_size 128;     client_header_buffer_size 32k;     large_client_header_buffers 4 32k;     client_max_body_size 8m;     sendfile        on;     tcp_nopush     on;     keepalive_timeout  60;          tcp_nodelay on;     fastcgi_connect_timeout 300;     fastcgi_send_timeout 300;     fastcgi_read_timeout 300;     fastcgi_buffer_size 64k;     fastcgi_buffers 4 64k;     fastcgi_busy_buffers_size 128k;     fastcgi_temp_file_write_size 128k;     gzip on;     gzip_min_length  1k;     gzip_buffers     4 16k;     gzip_http_version 1.0;     gzip_comp_level 2;     gzip_types       text/plain application/x-javascript text/css application/xml;     gzip_vary on; server {         listen       80;         server_name  test1.yunwei8.com;                  location / {                         include  uwsgi_params;             uwsgi_pass  127.0.0.1:9090;             uwsgi_param UWSGI_SCRIPT test1.wsgi;             uwsgi_param UWSGI_CHDIR /yunwei8/web/www/test1;             index  index.html index.htm;             client_max_body_size 35m;         }         error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }      } server {         listen       80;         server_name  test2.yunwei8.com;         location / {                         include  uwsgi_params;             uwsgi_pass  127.0.0.1:9091;             uwsgi_param UWSGI_SCRIPT test2.wsgi;             uwsgi_param UWSGI_CHDIR /yunwei8/web/www/test2;             index  index.html index.htm;    client_max_body_size 35m;         }         error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }      } }   12.6重启nginx #  service uwsgi9090 start #  service nginx restart   13:访问测试 首先在本地计算机中C:WindowsSystem32driversetc目录下Host文件下添加网址: 192.168.100.11    test1.yunwei8.com 192.168.100.11    test2.yunwei8.com 在浏览器内输入:http://test1.yunwei8.com、http://test2.yunwei8.com It worked! Congratulations on your first Django-powered page.

14:安装Mysqldb #  yum -y install mysql-devel #  easy_install-2.7 MySQL-python

六、配置nginx配置  在conf.d下建同域名相同的文件如:xxx.xxx.com.conf

server { listen 80; server_name data.teanet.im; #配置资源文件 location /resource { root /opt/webapps/data/; autoindex on; autoindex_exact_size on; autoindex_localtime on; allow all; } #重定向到uwsgi的配置 location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9090; uwsgi_param UWSGI_SCRIPT data.wsgi; uwsgi_param UWSGI_CHDIR /opt/webapps/; index index.html index.htm; client_max_body_size 35m; } }

转载请注明原文地址: https://www.6miu.com/read-53899.html

最新回复(0)