nginx在centos系统下安装以及nginx的伪静态安装配置
2013-06-07 15:45
639 查看
网上有详细的,不过不全,而且有些会容易忽略一些东西。以下是纯操作性的演示:
1. 安装gcc(编译用)
yum install gcc gcc-c++ autoconf make
2. 安装pcre
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar zxvf pcre-8.21.tar.gz
进入目录,然后三部曲
./configure --prefix=/usr/local/pcre
make
make install
cp /usr/local/pcre/lib/libpcre.a /usr/local/pcre/libpcre.a
cp /usr/local/pcre/lib/libpcre.la /usr/local/pcre/libpcre.la
cp /usr/local/pcre/include/pcre.h /usr/local/pcre/pcre.h
mkdir /usr/local/pcre/.libs
cp /usr/local/pcre/lib/libpcre.a /usr/local/pcre/.libs/libpcre.a
cp /usr/local/pcre/lib/libpcre.la /usr/local/pcre/.libs/libpcre.la
cp /usr/local/pcre/include/pcre.h /usr/local/pcre/.libs/pcre.h
(说明一下,这里最好是指定一下要安装的目录,除非你知道它装到哪里了)。
3. 安装openssl
yum install openssl openssl-devel
准备工作差不多了,开始安装nginx。
以root用户在CentOS的终端中输入以下命令,开始安装Nginx1.0.4。
1.
要建立 user:nginx 并加入:group=nginx ,为啥?因为后面编译的时候指定了用户和组。
命令:
#useradd -G nginx nginx
-g 和-G 的区别是-g是只分配一个组。
2.
#cd /usr/local/src/
#tar zxvf nginx-1.0.4.tar.gz
#cd nginx-1.0.4/
#./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --without-http_rewrite_module --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx/nginx.pid --with-pcre
#make
#make install
这一段是网上的段子,有两点错误:
首先,--without-http_rewrite_module 不可以有,加了这个意味着没有rewrite了。其次要指定with-pcre = pcre的安装目录,不是源码目录
所以上面那一段要改成:
#./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx/nginx.pid --with-pcre=/usr/local/pcre
成功后,make的时候会报错。所以需要在nginx-1.0.4目录下面修改一个文件:
#vi objs/Makefile
查找configure --disable-shared,在1089行,删除./configure --disable-shared, 保存
至此,nginx安装工作就完毕了,接下来配置:
添加下面的文件,让nginx 支持service 启动关闭。
vim /etc/init.d/nginxd/ 内容如下:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=₩([^ ]*₩).*/₩1/g'-`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0
{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
结束符esac是case的倒装,哈哈~
以root用户在CentOS的终端中输入以下命令
#chmod +x /etc/init.d/nginxd
#service nginxd start
#chkconfig --add nginxd
#chkconfig nginxd on
#chkconfig --list nginxd
通过浏览器访问服务器,出现welcome to nginx!表示成功。
最后:Nginx的启动和随机启动
service nginxd restart
把这句话加入到/etc/rc.local最后.
nginx优化以及如果抵扣小流量攻击后面贴出 .....
1. 安装gcc(编译用)
yum install gcc gcc-c++ autoconf make
2. 安装pcre
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar zxvf pcre-8.21.tar.gz
进入目录,然后三部曲
./configure --prefix=/usr/local/pcre
make
make install
cp /usr/local/pcre/lib/libpcre.a /usr/local/pcre/libpcre.a
cp /usr/local/pcre/lib/libpcre.la /usr/local/pcre/libpcre.la
cp /usr/local/pcre/include/pcre.h /usr/local/pcre/pcre.h
mkdir /usr/local/pcre/.libs
cp /usr/local/pcre/lib/libpcre.a /usr/local/pcre/.libs/libpcre.a
cp /usr/local/pcre/lib/libpcre.la /usr/local/pcre/.libs/libpcre.la
cp /usr/local/pcre/include/pcre.h /usr/local/pcre/.libs/pcre.h
(说明一下,这里最好是指定一下要安装的目录,除非你知道它装到哪里了)。
3. 安装openssl
yum install openssl openssl-devel
准备工作差不多了,开始安装nginx。
以root用户在CentOS的终端中输入以下命令,开始安装Nginx1.0.4。
1.
要建立 user:nginx 并加入:group=nginx ,为啥?因为后面编译的时候指定了用户和组。
命令:
#useradd -G nginx nginx
-g 和-G 的区别是-g是只分配一个组。
2.
#cd /usr/local/src/
#tar zxvf nginx-1.0.4.tar.gz
#cd nginx-1.0.4/
#./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --without-http_rewrite_module --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx/nginx.pid --with-pcre
#make
#make install
这一段是网上的段子,有两点错误:
首先,--without-http_rewrite_module 不可以有,加了这个意味着没有rewrite了。其次要指定with-pcre = pcre的安装目录,不是源码目录
所以上面那一段要改成:
#./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx/nginx.pid --with-pcre=/usr/local/pcre
成功后,make的时候会报错。所以需要在nginx-1.0.4目录下面修改一个文件:
#vi objs/Makefile
查找configure --disable-shared,在1089行,删除./configure --disable-shared, 保存
至此,nginx安装工作就完毕了,接下来配置:
添加下面的文件,让nginx 支持service 启动关闭。
vim /etc/init.d/nginxd/ 内容如下:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=₩([^ ]*₩).*/₩1/g'-`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0
{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
结束符esac是case的倒装,哈哈~
以root用户在CentOS的终端中输入以下命令
#chmod +x /etc/init.d/nginxd
#service nginxd start
#chkconfig --add nginxd
#chkconfig nginxd on
#chkconfig --list nginxd
通过浏览器访问服务器,出现welcome to nginx!表示成功。
最后:Nginx的启动和随机启动
service nginxd restart
把这句话加入到/etc/rc.local最后.
nginx优化以及如果抵扣小流量攻击后面贴出 .....
相关文章推荐
- nginx服务器的安装配置,以及防火墙配置,Centos7
- Centos6.5服务器环境搭建之安装Nginx以及Https访问方式的配置
- CentOS 6.5系统中安装配置Nginx服务器的方法
- 怎么保存退出vi编辑以及CentOS 7.0系统安装配置步骤详解
- 5、CentOS 6.5系统安装配置Nginx-1.2.7+PHP-5.3.22环境
- liunx系统安装nginx,以及配置、用到的简单指令
- CentOS-6.3系统中安装配置Web服务器Nginx
- CentOS系统安装配置Nginx+tomcat+jdk+MySQL服务器环境
- 保存退出vi编辑以及CentOS 系统安装配置步骤详解
- centos安装php php-fpm 以及 配置nginx
- CentOS6.5系统简单安装与配置Nginx服务器的方法
- Linux(CentOS7.2)下Python3安装配置和系统原python2共存以及Django配置搭建
- Ubuntu/CentOS 系统上安装与配置Nginx
- centos安装php php-fpm 以及 配置nginx
- centos 安装配置 rabbitmq 以及nginx转发
- centos安装php php-fpm 以及 配置nginx
- 一 centos 6.0 系统安装以及初始配置
- 阿里云CENTOS系统安装PHP+MYSQL+NGINX环境配置
- Ubuntu/CentOS 系统上安装与配置Nginx
- Nginx安装配置(系统平台:CentOS 7.1 64位)