安裝
1.安裝所需的依賴庫
yum install -y gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2.進(jìn)入官網(wǎng)獲取安裝資源 http://nginx.org/en/download.html

點(diǎn)擊鼠標(biāo)右鍵可獲取下載鏈接,然后使用wget進(jìn)行下載
wget http://nginx.org/download/nginx-1.14.2.tar.gz
3.安裝nginx
解壓 :tar -zxvf nginx-1.14.2.tar.gz
配置安裝 :./configure --prefix=/usr/local/nginx --pid-path=/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
編譯 :make
安裝 :?make install
默認(rèn)Nginx安裝在/usr/local/nginx/中,因此
/usr/local/nginx/sbin/nginx? ? ? ? ? ? ? ? ? #默認(rèn)啟動方式 start
/usr/local/nginx/sbin/nginx -t? ? ? ? ? ? ? ?#測試配置信息
/usr/local/nginx/sbin/nginx -v? ? ? ? ? ? ? #顯示版本信息,-V(大V)顯示編譯時的參數(shù)
/usr/local/nginx/sbin/nginx -s stop? ? ? #快速停止服務(wù)
/usr/local/nginx/sbin/nginx -s quit? ? ? ?#正常停止服務(wù)
/usr/local/nginx/sbin/nginx -s reload? ?#重啟
開放端口
永久開放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
創(chuàng)建啟動腳本
vi /etc/init.d/nginx
#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x?"$DAEMON"?] ||?exit?0
do_start() {
$DAEMON?-c?$CONFIGFILE?||?echo?-n?"nginx already running"
}
do_stop() {
$DAEMON?-s stop ||?echo?-n?"nginx not running"
}
do_reload() {
$DAEMON?-s reload ||?echo?-n?"nginx can't reload"
}
case?"$1"?in
start)
echo?-n?"Starting $DESC: $NAME"
do_start
echo?"."
;;
stop)
echo?-n?"Stopping $DESC: $NAME"
do_stop
echo?"."
;;
reload|graceful)
echo?-n?"Reloading $DESC configuration..."
do_reload
echo?"."
;;
restart)
echo?-n?"Restarting $DESC: $NAME"
do_stop
do_start
echo?"."
;;
*)
echo?"Usage: $SCRIPTNAME {start|stop|reload|restart}"?>&2
exit?3
;;
esac
exit?0
設(shè)置執(zhí)行權(quán)限?
chmod a+x /etc/init.d/nginx?
注冊成服務(wù)?
chkconfig --add nginx?
設(shè)置開機(jī)啟動?
chkconfig nginx on?
配置文件
主配置文件?/usr/local/nginx/conf/nginx.conf
引入外部配置文件
假設(shè)外部配置文件存放的目錄為?/usr/local/nginx/conf/extend/ ,文件名為?extend.conf。則在主配置文件的末尾(右花括號上面)追加?
include /usr/local/nginx/conf/extend/extend.conf;