设为首页 收藏本站
查看: 674|回复: 0

[经验分享] Python 2.6+Django 1.2.1 + Nginx

[复制链接]

尚未签到

发表于 2018-11-15 07:43:46 | 显示全部楼层 |阅读模式
  Python 2.6.5 + Django 1.2.1 + Nginx Installation && Configuration
  
fastcgi+django,fastcgi+php
  一、install
  
## 万恶的XXX,封掉了python下的所有目录,首页上的download链接是打不开的,不过可以到其他的链接下载 ##
  
## 1、http://ftp.python.org/ftp/python/2.6.5/
  
## 2、http://www.python.org/ftp/python/
  1. Python 2.6.5
  
1) install
  


  • wget http://ftp.python.org/ftp/python/2.6.5/Python-2.6.5.tgz

  • tar zxvf Python-2.6.5.tgz
  • cd Python-2.6.5
  • ./configure --prefix=/opt/python26
  • make
  • make install

  • ln -s /opt/python26/bin/python2.6 /usr/bin/python26
  

  ## add the /opt/python26/bin to the PATH
  vi /etc/profile
  ###########################
  PATH=”$PATH:/opt/mysql/bin:/opt/python/bin:/opt/nginx/sbin:/opt/python26/bin”;export PATH
  ###########################
  2)test
  


  • [root@devel photo_uw]# python26
  • Python 2.6.5 (r265:79063, Jul 20 2010, 10:39:03)
  • [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>>
  

  —————————————————————-
  2. PIL
  1) install
  


  • wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz

  • tar zxvf Imaging-1.1.7.tar.tar
  • cd Imaging-1.1.7
  • python26 setup.py build_ext -i
  • python26 setup.py install
  • cd ..
  

  2) test
  


  • [root@devel photo_uw]# python26
  • Python 2.6.5 (r265:79063, Jul 20 2010, 10:39:03)
  • [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import Image
  • >>>
  

  —————————————————————-
  3. setuptools
  


  • wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz

  • tar zxvf setuptools-0.6c11.tar.gz
  • cd setuptools-0.6c11
  • python26 setup.py install
  • cd ..
  

  —————————————————————-
  4. flup
  


  • wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

  • tar zxvf flup-1.0.2.tar.gz
  • cd flup-1.0.2
  • python26 setup.py install
  • cd ..
  

  —————————————————————-
  5. MySQL-python
  1) install
  


  • wget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz

  • tar zxvf MySQL-python-1.2.3c1.tar.gz
  • cd MySQL-python-1.2.3c1
  • python26 setup.py build
  • python26 setup.py install
  • cd ..
  

  2) test
  


  • [root@devel photo_uw]# python26
  • Python 2.6.5 (r265:79063, Jul 20 2010, 10:39:03)
  • [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import MySQLdb
  • >>>
  

  测试出现ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory时,需将mysql/lib/目录下文件,链接到/usr/lib目录下
  


  • ln -s /usr/local/mysql/lib/libmysqlclient* /usr/lib
  • ldconfig
  

  —————————————————————-
  6 Django 1.2.1
  1) install
  


  • wget http://media.djangoproject.com/releases/1.2/Django-1.2.1.tar.gz

  • tar zxvf Django-1.2.1.tar.gz
  • cp -R Django-1.2.1 /opt/python26
  • cd /opt/python26/lib/python2.6/site-packages/
  • ln -s /opt/python26/Django-1.2.1/django django
  

  or
  


  • cd Django-1.2.1
  • python26 setup.py install
  

  2) test
  


  • [root@devel photo_uw]# python26
  • Python 2.6.5 (r265:79063, Jul 20 2010, 10:39:03)
  • [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import django
  • >>> django.get_version()
  • '1.2.1'
  

  7. django-treebeard
  1) install
  


  • wget http://pypi.python.org/packages/source/d/django-treebeard/django-treebeard-1.61.tar.gz

  • tar zxvf django-treebeard-1.61.tar.gz
  • cd django-treebeard-1.61
  • python26 setup.py install
  

  2) test
  


  • [root@devel photo_uw]# python26
  • Python 2.6.5 (r265:79063, Jul 20 2010, 10:39:03)
  • [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
  • Type "help", "copyright", "credits" or "license" for more information.
  • >>> import treebeard
  • >>>
  

  二. configure
  1) nginx
  


  • cd /opt/nginx/conf/vhosts

  • vi vhost-www_tech.conf

  • --------------------------------------------------------------------
  •     upstream backend_www_tech {
  •         #server unix:/var/run/fcgi/www/www_tech.sock;
  •         server unix:/var/run/fcgi/www_tech.sock;
  •     }

  •     server {
  •         listen       192.168.0.250;
  •         server_name  192.168.0.250;

  •         #charset gb2312;

  •         access_log  /var/log/nginx/www_tech/www_tech_access_log combined;
  •         error_log   /var/log/nginx/www_tech/www_tech_error_log notice;

  •         location / {
  •             root        /infoware/www_tech/web;
  •             #allow  all;
  •             #fastcgi_pass    backend_dorm;
  •             fastcgi_pass    backend_www_tech;
  •             fastcgi_param   PATH_INFO       $fastcgi_script_name;
  •             fastcgi_param   REMOTE_ADDR     $remote_addr;
  •             fastcgi_pass_header             Authorization;
  •             include         fastcgi_params_django;

  •         }

  •         location /static {
  •             root            /infoware/www_tech/web;
  •         }

  •         error_page  404     http://192.168.0.250/static/error404.htm;
  •     }
  

  ####################################################################
  ## 这里不能使用nginx默认的fastcgi_params,测试的时候发现所有的页面都会跳转到首页,而且也不报错
  ## 貌似是SCRIPT_NAME所引起的问题,而Django好像使用的是PATH_INFO,为了避免和其他的fcgi冲突,所以新建一个django专用的fastcgi_params_django
  ## Python2.4 + Django 0.96 版本不需要,因为Django 0.96 还不支持SCRIPT_NAME
  ## 可以查看django的django\core\handlers目录下的modpython.py 文件
  


  • vi /opt/nginx/conf/fastcgi_params_django

  • fastcgi_param  PATH_INFO          $fastcgi_script_name;
  • 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  SERVER_PROTOCOL    $server_protocol;
  • # fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  • # fastcgi_param  REQUEST_URI        $request_uri;
  • # fastcgi_param  DOCUMENT_URI       $document_uri;
  • # fastcgi_param  DOCUMENT_ROOT      $document_root;
  • 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;
  

  2) fcgi
  


  • cd /infoware/_conf/www_tech/

  • vi start_www_tech.sh
  • ------------------------------------------------------------------
  • #!/bin/bash

  • ## start_www_tech.sh: start www_tech app in django fcgi mode
  • ## ljzhou, 2010.08.26

  • ## TODO
  • #  - executed under deamontools(in method=thread mode), to get
  • #    (1) controled env (2) 'web' uid (3) monitored process
  • #  - dormctl.sh script(nginx+django?), just as apachectl

  • APP_DIR="/infoware/www_tech/web"
  • CFG_DIR="/infoware/_conf/www_tech"

  • PYTHON="/usr/bin/python26"
  • DJANGO_ADMIN="/opt/python26/lib/python2.6/site-packages/django/bin/django-admin.py"
  • #PYTHON="/opt/python/bin/python2"
  • #DJANGO_ADMIN="/usr/lib/python2.4/site-packages/django/bin/django-admin.py"

  • ############### no config below this line ##################
  • export PYTHONPATH="$PYTHONPATH:$CFG_DIR"
  • # mysettings.py in $CFG_DIR
  • #export DJANGO_SETTINGS_MODULE=mysettings
  • export DJANGO_SETTINGS_MODULE=settings

  • umask 027

  • ## server: self daemonized, total num=20 with 10 threads each
  • ## Help message:   help
  • ## TCP socket  :   host=... port=...
  • PIDFILE="/var/run/fcgi/www_tech.pid"
  • if [ -f $PIDFILE ]; then
  •     kill `cat -- $PIDFILE`
  •     rm -f -- $PIDFILE
  •     sleep 3
  • fi

  • $PYTHON $DJANGO_ADMIN \
  •     runfcgi daemonize=true method=prefork \
  •     maxspare=5 minspare=2 maxchildren=10 maxrequests=500 \
  •     socket="/var/run/fcgi/www_tech.sock" pidfile=$PIDFILE \
  •     umask=000 debug=true \
  •     --pythonpath=$APP_DIR

  • # EOF: start_www_tech.sh

  • ------------------------------------------------------------------
  • stop script like this , only Remark those:

  • #$PYTHON $DJANGO_ADMIN \
  • #    runfcgi daemonize=true method=prefork \
  • #    maxspare=5 minspare=2 maxchildren=10 maxrequests=500 \
  • #    socket=&"/var/run/fcgi/www_tech.sock" pidfile=$PIDFILE \
  • #    umask=000 debug=true \
  • #    --pythonpath=$APP_DIR
  




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-635160-1-1.html 上篇帖子: Nginx启动出错 下篇帖子: NGINX与APACHE工作模式的区别
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表