在公司的suse服务器装nginx,记录下安装过程:
参照这篇文章:Linux 从源码编译安装 Nginx:
1.1、准备 pcre 库
pere 是为了让 nginx 支持正则表达式。只是准备,并不安装,是为了避免在64位系统中出现错误。
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.11.tar.gz
tar -zxf pcre-8.11.tar.gz
1.3、准备 zlib 库
同样只是准备,并不安装,是为了避免在64位系统中出现错误。
wget http://zlib.net/zlib-1.2.5.tar.gz
tar -zxf zlib-1.2.5.tar.gz
2.1、下载、创建临时目录
wget http://nginx.org/download/nginx-1.5.5.tar.gz //在公司是下载到本地再rz -by上传到服务器
tar -zxf nginx-1.5.5.tar.gz
cd nginx-1.5.5
mkdir -p /var/tmp/nginx
2.2、编译与安装
详细编译配置选项见《Nginx编译参数解析》
root64:~ # ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-mail --with-pcre=../pcre-8.11 --with-zlib=../zlib-1.2.5 --with-debug --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi
root64:~ # make && make install
root64:~ # ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
--prefix #nginx安装目录,默认在/usr/local/nginx
--pid-path #pid问件位置,默认在logs目录
--lock-path #lock问件位置,默认在logs目录
--with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
--with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
--with-http_flv_module #支持对FLV文件的拖动播放
--with-http_realip_module #支持显示真实来源IP地址
--with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
--with-http_stub_status_module #取得一些nginx的运行状态
--with-mail #允许POP3/IMAP4/SMTP代理模块
--with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
--with-pcre=../pcre-8.11 #注意是未安装的pcre路径
--with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径
--with-debug #允许调试日志
--http-client-body-temp-path #客户端请求临时文件路径
--http-proxy-temp-path #设置http proxy临时文件路径
--http-fastcgi-temp-path #设置http fastcgi临时文件路径
--http-uwsgi-temp-p(www.111cn.net)ath=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
--http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径
2.3、开机自启动 nginx 脚本
/etc/init.d/nginx
#! /bin/bash
# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and
# chkconfig --add nginx && chkconfig nginx on
# then you can use server command control nginx
#
# chkconfig: 2345 08 99
# description: Starts, stops nginx
set -e
PATH=$PATH:/usr/local/nginx/sbin/
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
将nginx添加到自启动服务中并启动:
chmod 700 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
/etc/init.d/nginx start
再配置每天自动切割nginx日志脚本:
vi /usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path="/usr/local/nginx/logs/"
logs_bak_path="/data/logs/nginx/"
mkdir -p ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
cp ${logs_path}access.log ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
rm -rf ${logs_path}*.log
kill -USR1 `cat /var/run/nginx.pid`
(责任编辑:IT) |