我是条汉子 发表于 2018-8-9 06:46:43

python+django+nginx配置

  python2.4+django0.96+nginx
  1、1. Python 2.4.3
  1) install
  wget http://www.python.org/ftp/python/2.4/Python-2.4.3.tar.bz2
  tar jxvf Python-2.4.3.tar.bz2
  cd Python-2.4.3
  ./configure --prefix=/opt/python
  make
  make install
  rm -rf /usr/bin/python
  ln -s /opt/python/bin/python /usr/bin/python
  2)test
  # /opt/python/bin/python
  Python 2.4.3 (#1, Apr 11 2012, 15:32:09)
   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
  /opt/python/bin/python setup.py build_ext -i
  /opt/python/bin/python setup.py install
  cd ..
  2) test
  # /opt/python/bin/python
  Python 2.4.3 (#1, Apr 11 2012, 15:32:09)
   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
  /opt/python/bin/python 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
  /opt/python/bin/python setup.py install
  cd ..
  —————————————————————-
  下面步骤之前必须要安装完mysql,并且能够正常启动。
  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
  /opt/python/bin/python setup.py build
  /opt/python/bin/python setup.py install
  cd ..
  2) test
  # /opt/python/bin/python
  Python 2.4.3 (#1, Apr 11 2012, 15:32:09)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import MySQLdb
  如下:
  “ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory”
  解决办法:把/usr/local/mysql5/lib/mysql加到LD_LIBRARY_PATH环境变量中
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql5/lib/mysql
  —————————————————————-
  6 Django django_0.96
  1) install
  tar zxvf django_0.96_bugfixes.tar.gz
  cp -R django_0.96_bugfixes /opt/python
  cd /opt/python/lib/python/site-packages/
  ln -s /opt/python26/django_0.96_bugfixes/django django
  or
  cd django_0.96_bugfixes
  /opt/python/bin/python setup.py install
  2) test
  # /opt/python/bin/python
  Python 2.4.3 (#1, Apr 11 2012, 15:32:09)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import django
  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
  /opt/python/bin/python setup.py install
  2) test
  # /opt/python/bin/python
  Python 2.4.3 (#1, Apr 11 2012, 15:32:09)
   on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import treebeard
  >>>
  二. nginx安装配置(详见nginx安装)
  1) nginx
  upstream backend_www {
  server unix:/var/run/fcgi/www.sock;
  }
  server {
  listen       192.168.0.2;
  server_name192.168.0.2;
  access_log/var/log/nginx/www/www_access_log combined;
  error_log   /var/log/nginx/www/www_error_log notice;
  location / {
  root      /data/www/web;
  #allowall;
  #fastcgi_pass    backend_dorm;
  fastcgi_pass    backend_www;
  fastcgi_param   PATH_INFO       $fastcgi_script_name;
  fastcgi_param   REMOTE_ADDR   $remote_addr;
  fastcgi_pass_header             Authorization;
  include         fastcgi_params;
  }
  Python2.6.5 + Django 1.2.1版本需要新建一个django专用fastcgi_params_django,
  可以查看django的django\core\handlers目录下的modpython.py 文件
  vi /opt/nginx/conf/fastcgi_params_django
  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_paramSERVER_PROTOCOL    $server_protocol;
  # fastcgi_paramSCRIPT_NAME      $fastcgi_script_name;
  # fastcgi_paramREQUEST_URI      $request_uri;
  # fastcgi_paramDOCUMENT_URI       $document_uri;
  # fastcgi_paramDOCUMENT_ROOT      $document_root;
  fastcgi_paramGATEWAY_INTERFACECGI/1.1;
  fastcgi_paramSERVER_SOFTWARE    nginx/$nginx_version;
  fastcgi_paramREMOTE_ADDR      $remote_addr;
  fastcgi_paramREMOTE_PORT      $remote_port;
  fastcgi_paramSERVER_ADDR      $server_addr;
  fastcgi_paramSERVER_PORT      $server_port;
  fastcgi_paramSERVER_NAME      $server_name;
  2) fcgi
  vi /data/_conf/www/start_www.sh
  ------------------------------------------------------------------
  #!/bin/bash
  APP_DIR="/data/www/web"
  CFG_DIR="/data/_conf/www"
  PYTHON="/usr/bin/python2"
  DJANGO_ADMIN="/opt/python/lib/python2.4/site-packages/django/bin/django-admin.py"
  export DJANGO_SETTINGS_MODULE=mysettings
  umask 027
  PIDFILE="/var/run/fcgi/www.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.sock" pidfile=$PIDFILE \
  umask=000 debug=true \
  --pythonpath=$APP_DIR
  ------------------------------------------------------------------
页: [1]
查看完整版本: python+django+nginx配置