<fieldset id='qfxtc'></fieldset>

<code id='qfxtc'><strong id='qfxtc'></strong></code>
        <span id='qfxtc'></span>
        <acronym id='qfxtc'><em id='qfxtc'></em><td id='qfxtc'><div id='qfxtc'></div></td></acronym><address id='qfxtc'><big id='qfxtc'><big id='qfxtc'></big><legend id='qfxtc'></legend></big></address>

        1. <tr id='qfxtc'><strong id='qfxtc'></strong><small id='qfxtc'></small><button id='qfxtc'></button><li id='qfxtc'><noscript id='qfxtc'><big id='qfxtc'></big><dt id='qfxtc'></dt></noscript></li></tr><ol id='qfxtc'><table id='qfxtc'><blockquote id='qfxtc'><tbody id='qfxtc'></tbody></blockquote></table></ol><u id='qfxtc'></u><kbd id='qfxtc'><kbd id='qfxtc'></kbd></kbd>

          <i id='qfxtc'></i>

          <dl id='qfxtc'></dl>
        2. <i id='qfxtc'><div id='qfxtc'><ins id='qfxtc'></ins></div></i>

          <ins id='qfxtc'></ins>

          Linux系统上Nginx+Python的web.py与Django框架环境

          • 时间:
          • 浏览:8
          • 来源:124软件资讯网

              1.编译nginx

              在网上买了一本《实战nginx-取代Apache的高性能服务器》  ,写的比力浅  ,主要是些设置方面的工具  ,不外却正是现在我所需要的  。由于需要支持https和rewrite ,以是除了nginx的源码之外  ,又下载了 openssl-0.9.8r.tar.gz 和 pcre-8.12.tar.gz  ,把他们和nginx-1.0.4.tar.gz放到统一个目录  。

              为了利便编译  ,笔者写了一个剧本 ,代码如下:

              ?

            1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #!/bin/bash #============================================================================= #剧本所在绝对目录 abs_path(){ local path=$1 local basename=$( basename $path ) local dirname=$( dirname $path ) cd $dirname if [ -h $basename ]; then path=$( readlink $basename ) abs_path $path else pwd fi } #============================================================================= #依赖的目录 src_base_dir=$( abs_path $0 ) src_openssl_dir=$src_base_dir'/openssl-0.9.8r' src_pcre_dir=$src_base_dir'/pcre-8.12' src_nginx_dir=$src_base_dir'/nginx-1.0.4' #============================================================================= #目的的目录 dest_base_dir=$src_base_dir'/release' dest_nginx_dir=$dest_base_dir'/nginx' #============================================================================= #把所有的tar.gz解压 find . -name "*.tar.gz" | xargs -IX tar zxvf X #============================================================================= #编译nginx cd $src_nginx_dir chmod u+x ./configure ./configure --with-http_stub_status_module --with-http_ssl_module --with-openssl=$src_openssl_dir --with-pcre=$src_pcre_dir --prefix=$dest_nginx_dir make && make install

              2.设置nginx

              在server设置项下增添

              ?

            1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 location / { #这两种要领都可以  ,只不外spawn-cgi启动的要领差别 #fastcgi_pass 127.0.0.1:9002; fastcgi_pass unix:webpy.sock; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; }

              这里的3个location设置划分解决了  ,与python历程通讯、django后台治理端样式存放、网站样式存放的问题  。对照着apache的设置来看 ,就很容易明确了

              ?

            1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 WSGIPythonEggs /tmp ServerName fuload.qq.com WSGIScriptAlias / /home/dantezhu/htdocs/fuload/conf/setting.wsgi Options FollowSymLinks AllowOverride Order allow,deny Allow from all Order Deny,Allow Deny from all Alias /admin_media "/usr/local/lib/python2.7/site-packages/django/contrib/admin/media" Order allow,deny Options Indexes Allow from all IndexOptions FancyIndexing #AliasMatch /site_media/(.*\.(css|gif|png|jpg|jpeg)) /home/dantezhu/htdocs/fuload/media/$1 Alias /site_media /home/dantezhu/htdocs/fuload/media/ Order allow,deny Options Indexes Allow from all IndexOptions FancyIndexing

              3.安装fastcgi依赖

              需要到 http://trac.saddi.com/flup下载安装  ,之后fastcgi才气够正常启动  。

              4.启动django

              建立django project的历程我们就不说了  ,只列出启动/制止的下令:

              启动:

              ?

            1 2 #python manage.py runfcgi daemonize=true pidfile=`pwd`/django.pid host=127.0.0.1 port=9001 maxrequests=1 & python manage.py runfcgi daemonize=true pidfile=`pwd`/django.pid socket=/home/dantezhu/nginx/sbin/django.sock maxrequests=1 &

              制止:

              ?

            1 kill -9 `cat django.pid`

              启动nginx

              启动:

              ?

            1 ./nginx -p /home/dantezhu/nginx/

              制止:

              ?

            1 kill -QUIT `cat ../logs/nginx.pid`

              重新载入设置:

              ?

            1 2 ./nginx -t -c `pwd`/../conf/nginx.conf kill -HUP `cat ../logs/nginx.pid`

              乐成显示了django的后台界面:

              PPPPPPPPPPPPPPPPPPPPP1

              5.部署web.py版

              安装依赖

              spawn-cgi

              flup

              设置nginx

              在server设置项下增添

              ?

            1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 location / { #这两种要领都可以  ,只不外spawn-cgi启动的要领差别 #fastcgi_pass 127.0.0.1:9002; fastcgi_pass unix:webpy.sock; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; }

              一个简朴的index.py

              ?

            1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/usr/bin/python # -*- coding: utf-8 -*- import web urls = ("/.*", "hello") app = web.application(urls, globals()) class hello: def GET(self): return 'Hello, world!' if __name__ == "__main__": web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr) app.run()

              并执行:

              ?

            1 chmod +x index.py

              .启动web.py

              启动:

              ?

            1 2 #spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -a 127.0.0.1 -p 9002 & spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -s /home/dantezhu/nginx/sbin/webpy.sock &

              制止:

              ?

            1 kill -9 `cat webpy.pid`

              启动nginx

              加入到rc.local中  ,自动启动

              ?

            1 2 3 /home/dantezhu/nginx/sbin/start.sh sudo -u dantezhu /home/dantezhu/htdocs/ngx_django/mysite/start.sh sudo -u dantezhu /home/dantezhu/htdocs/ngx_web/start.sh