centos6.8 下nginx1.10 安裝
在安裝nginx前,需要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel軟體。
安裝必須軟體:
# yum install gcc-c++
# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
# yum install -y gd-devel
# yum -y install openssl openssl-devel
解壓檔案:tar -zxvf /home/rpm/nginx/nginx-1.10.0.tar.gz -C /home/rpm/nginx
重新命名:mv /home/rpm/nginx/nginx-1.10.0 /home/rpm/nginx/nginx1.10
cd /home/rpm/nginx/nginx1.10
ssl證書 https
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
圖片裁剪配置一起
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_image_filter_module(注:處此是指定nginx的安裝目錄,大多使用者習慣於安裝在/usr/local/nginx下面)
# make 編譯
# make install 安裝
啟動 :# /usr/local/nginx/sbin/nginx
重啟服務: /usr/local/nginx/sbin/nginx -s reload
阿里雲伺服器開啟防火牆
開啟防火牆
[[email protected] ~]# ls /etc/sysconfig/iptables*
/etc/sysconfig/iptables-config
[[email protected] ~]# iptables -F
[[email protected] ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[[email protected] ~]# ls /etc/sysconfig/iptables*
/etc/sysconfig/iptables /etc/sysconfig/iptables-config
**************************************************************************************************
新增防火牆規則: vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重啟防火牆服務 service iptables restart
設定開機啟動:
新增shell指令碼 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
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"
}
d_reload() {
$DAEMON -s reload || echo -n " counld not 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 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
將該shell加入系統服務即可(或把nginx指令碼檔案放在/etc/rc.d/init.d/目錄下)
chmod +x /etc/rc.d/init.d/nginx (設定可執行許可權)
chkconfig --add nginx (新增系統服務)
驗證是否成功 /etc/init.d/nginx start
或者 service nginx start