wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar -zxvf xx -C 路径 指定解压路径
cd 目录
yum -y install gcc(安装过忽略)
yum install -y pcre pcre-devel(pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库)
yum install -y zlib zlib-devel(zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装)
yum install -y openssl openssl-devel(openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔)
指定目录(用来存放sbin等文件,不指定默认是usr/local/nginx,多个nginx时应该指定)
./configure --prefix=/usr/local/nginx1
编译
make
make install
或者make && make install
这样在nginx1根目录就出现sbin等文件了
切换到 nginx1目录 ,修改配置文件 也就是端口
启动
cd nginx1/sbin
./nginx
ps -ef | grep nginx 查看是否启动
=======以下为多nginx开机启动配置=============
nginx启动报错Starting bigdata_nginx (via systemctl): Job for bigdata_nginx.service failed. See "systemctl status bigdata_nginx.service" and "journalctl -xe" for details.
//按照提示,执行此命令,查看错误原因 systemctl status nginx.service
配置开机自启动
vi /etc/init.d/nginx_实例号 不同实例创建不同文件
vi /etc/init.d/nginx2
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: 2345 88 12
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
#
# processname: nginx
# config: /usr/local/nginx2/conf/nginx.conf #修改为自定义安装路径
# pidfile: /usr/local/nginx2/logs/nginx2.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/local/nginx2/sbin/nginx2" #修改为自定义路径
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx2/conf/nginx.conf" #修改为自定义路径
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx2.lock #修改为自定义名称如global-nginx.lock
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
}
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)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
;;
esac
chmod +x /etc/init.d/nginx2
chkconfig --add nginx2 && chkconfig nginx2 on
chkconfig --list nginx2
service nginx2 start 或使用 systemctl start nginx2
service nginx2 status 或使用 systemctl status nginx2
ps -ef|grep nginx2
service nginx2 stop 或使用 systemctl stop nginx2
测试时service nginx2 start 启动卡住,但成功了。导致关闭不了
systemctl 暂无异常情况
配置一个,剩下的重复以上步骤配置即可