Debian初学者笔记(3)— 安装nginx

作者:sealinger 发布时间:January 1, 2011 分类:混口饭吃

安装环境:sealinger@Debian 5.0.6 32位

1、安装PHP、MySQL


这里仅示例查找软件名称和安装的方法,需要安装哪些包,由你自己的需求决定。
1)安装PHP:

sealinger:~# apt-cache search php5

然后自己查看需要的包的名字,安装即可。

nginx调用php使用fcgi模式,故只需安装php5-cgi即可:

sealinger:~# apt-get install php5-cgi

The following NEW packages will be installed:
  php5-cgi php5-common

2)安装MySQL:

sealinger:~# apt-get install mysql-server mysql-client php5-mysql

The following NEW packages will be installed:
  libdbd-mysql-perl libhtml-template-perl libterm-readkey-perl
  mysql-client mysql-client-5.0 mysql-server mysql-server-5.0 php5-mysql

2、安装 nginx


**********网上参考 ***********************
下面开始在debian 下部署nginx
首先不需要太多包,只需要 pcre, ssl and zlib
 aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev*****************************************

1)先安装一些依赖包:


# dpkg -l |grep zlib
ii  zlib1g    1:1.2.3.3.dfsg-12    compression library - runtime

# apt-cache search zlib.*-dev
zlib1g-dev - compression library - development

# apt-get install zlib1g-dev

# apt-get install libssl-dev

安装 pcre :
# apt-get install libpcre3-dev
  libpcre3-dev libpcrecpp0

2)再安装nginx:


准备accesskey模块(防盗链模块,可选):
$ wget http://wiki.nginx.org/images/5/51/Nginx-accesskey-2.0.3.tar.gz
$ tar zxvf ../pkgs/Nginx-accesskey-2.0.3.tar.gz

Unpack, edit the "config" file, replace "$HTTP_ACCESSKEY_MODULE" with "ngx_http_accesskey_module", and then compile nginx with:  ./configure --add-module=path/to/nginx-accesskey
$ vi nginx-accesskey-2.0.3/config

USE_MD5=YES
USE_SHA1=YES
ngx_addon_name=ngx_http_accesskey_module
HTTP_MODULES="$HTTP_MODULES ngx_http_accesskey_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_accesskey_module.c"

开始编译安装nginx:
$ wget http://nginx.org/download/nginx-0.8.32.tar.gz
$ tar zxvf ../pkgs/nginx-0.8.32.tar.gz
$ cd nginx-0.8.32/
$ vi auto/cc/gcc   #注释掉debug模式

# debug
#CFLAGS="$CFLAGS -g"

./configure \
 --prefix=/home/ligb/nginx \
 --with-http_stub_status_module \
 --with-http_ssl_module \
 --add-module=../nginx-accesskey-2.0.3/

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/home/ligb/nginx"
  nginx binary file: "/home/ligb/nginx/sbin/nginx"
  nginx configuration prefix: "/home/ligb/nginx/conf"
  nginx configuration file: "/home/ligb/nginx/conf/nginx.conf"
  nginx pid file: "/home/ligb/nginx/logs/nginx.pid"
  nginx error log file: "/home/ligb/nginx/logs/error.log"
  nginx http access log file: "/home/ligb/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"

$ make && make install

========= 配置 ulimit -n =================
# vi /etc/security/limits.conf
* - nofile 8192

========= 安装 spawn-fcgi ================
$ wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
$ tar zxvf ../pkgs/spawn-fcgi-1.6.3.tar.gz
$ cd ./spawn-fcgi-1.6.3/
$ ./configure --prefix=/home/ligb/spawn-fcgi
$ make && make install

启动 php-cgi:
$ cd spawn-fcgi-1.6.3/bin/
$ ./spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi -P fastcgi-php.pid

======== 配置 nginx 维护脚本 =================
$ wget http://topfunky.net/svn/shovel/nginx/init.d/nginx

======== 配置 nginx ==========================

具体网上很多,建议参考张老师的吧。我自己就记录一个点:

开始打开.php文件,提示 “No input file specified”,是 SCRIPT_FILENAME 没有设置正确,改为如下OK:

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

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