准备工作,安装依赖库
//检查并安装组件
yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake
几点说明:
pcre、openssl、zlib是安装nginx时需要的
cmake是安装mysql时需要的
一、查看linux版本
[root@centos src]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \
二、编译安装nginx
1、下载nginx(stable版本)
wget -P /tmp http://nginx.org/download/nginx-1.8.1.tar.gz
-P指定下载文件目录
或者
[root@centos /]# cd /usr/local/src
[root@centos src]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
默认下载到当前目录下
2、解压nginx
[root@centos src]# tar xf nginx-1.8.1.tar.gz
[root@centos src]# cd nginx-1.8.1
[root@centos nginx-1.8.1]# ./configure --help(查看参数)
3、编译nginx
如果指定用户和用户组,需要先创建
//创建用户www和用户组www
groupadd www
useradd -g www www
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module
make && make install
//启动nginx
**第一种方式 指定--sbin-path=/usr/sbin/nginx**
nginx //启动
nginx -s stop// 停止
nginx -s reload // 重新加载
**第二种方式 不指定--sbin-path**
cd /usr/local/nginx
./sbin/nginx
重启nginx /usr/local/nginx/sbin/nginx -s reload
**第三种方式**
配置开机启动
首先写一个shell脚本,脚本名称:nginx
vi /etc/rc.d/init.d/nginx
#! /bin/bash
# chkconfig: 35 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME (这里是nginx安装是 --sbin-path指定的路径)
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
$DAEMON || echo -n " already running"
}
d_stop() {
$DAEMON -s quit || echo -n " not running"
}