在 Debian 上安装 Nginx

2009-08-11  21:35  |  分类:应用技术  |  标签:  |  1,712 次浏览

安装依赖的包:
apt-get install libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

下载最新稳定版安装:

wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
tar zxvf nginx-0.7.61.tar.gz
cd nginx-0.7.61
./configure \
--user=www-data \
--group=www-data \
--prefix=/usr/local/nginx \
--with-http_stub_status_module

make
make install

Nginx 的设置:
mkdir /var/log/nginx
vi /usr/local/nginx/conf/nginx.conf

user  www-data www-data;

worker_processes  2;

worker_cpu_affinity 01 10;

worker_rlimit_nofile  65536;

error_log  /var/log/nginx/error.log;

pid  /var/run/nginx.pid;

events {
    use  epoll;
    worker_connections  65536;
}

http {
    include  mime.types;
    default_type  text/html;

    access_log  /var/log/nginx/access.log combined;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_min_length  1100;
    gzip_buffers  4 8k;
    gzip_types  text/css text/xml application/x-javascript text/plain;
    gzip_comp_level  9;
    gzip_proxied  any;
    gzip_vary  on;
    gzip_http_version  1.0;

    output_buffers  4 32k;
    postpone_output  1460;

    client_header_buffer_size  128k;
    large_client_header_buffers  4 256k;

    fastcgi_buffers  8 128k;

    client_header_timeout  1m;
    client_body_timeout    1m;
    client_max_body_size   8m;
    send_timeout           1m;

    server {
        listen       80;
        server_name  _;
        root  /home/www;
        location ~ .*\.php?$ {
            fastcgi_pass  127.0.0.1:9000;
            include  fastcgi_params;
        }
        location ~* ^.+.(jpg|gif|png)$ {
            expires  30d;
        }
        location /server-status {
            stub_status  on;
        }
    }
}

并在 /usr/local/nginx/conf/fastcgi_params 中增加如下一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

创建启动脚本:
vi /etc/init.d/nginx

#! /bin/sh
 
###
BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
###
END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
 
test -x $DAEMON || exit 0
 
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /
etc/default/nginx
fi
 
set -e
 
case "$1" in
 
start)
        
echo -n "Starting $DESC: "
        
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --
exec $DAEMON -- $DAEMON_OPTS || true
        
echo "$NAME."
        ;;
 
stop)
        
echo -n "Stopping $DESC: "
        
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
                --
exec $DAEMON || true
        
echo "$NAME."
        ;;
 
restart|force-reload)
        
echo -n "Restarting $DESC: "
        
start-stop-daemon --stop --quiet --pidfile \
                /
var/run/$NAME.pid --exec $DAEMON || true
        
sleep 1
        
start-stop-daemon --start --quiet --pidfile \
                /
var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
        
echo "$NAME."
        ;;
 
reload)
      
echo -n "Reloading $DESC configuration: "
      
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
          --
exec $DAEMON || true
      
echo "$NAME."
      ;;
  *)
        
N=/etc/init.d/$NAME
        
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
        
exit 1
        ;;
esac
 
exit 0

chmod +x /etc/init.d/nginx

系统的相关设置:

echo -ne "
fs.file-max = 65536
" >> /etc/sysctl.conf
sysctl -p

echo -ne "
www-data soft nofile 65536
www-data hard nofile 65536
" >> /etc/security/limits.conf

启动:
/etc/init.d/nginx start

最后,设置 nginx 开机自启动:

sysv-rc-conf nginx on

sysv-rc-conf --list nginx
nginx        2:on       3:on    4:on    5:on
喜欢本文,那就收藏到: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

发表您的评论