新聞中心
centos編譯安裝Nginx

陽東ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
下載
wget http://nginx.org/download/nginx-1.9.6.tar.gz
解壓縮
tar zxvf nginx-1.9.6.tar.gz
進入nginx目錄
cd nginx-1.9.6
設置,編譯,安裝(configure過程可能出現(xiàn)的情況,見文章最尾)
./configure --prefix=/data/server/nginx
make && make install && make clean
修改nginx配置文件
vi /data/server/nginx/conf/nginx.conf1
將根目錄修改至 /data/webroot/localhost
找到
location / {
root html; # 根目錄
index index.html index.htm; # 默認文檔
}
改為
location / {
root /data/webroot/localhost; # 站點根目錄路徑
index index.html index.htm; # 目前只放靜態(tài)頁,所以不需要改
}
創(chuàng)建nginx系統(tǒng)服務腳本
vi /etc/init.d/nginx
填入如下內(nèi)容
#!/bin/sh
#
#nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /data/webroot/logs/localhost/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="/data/server/nginx/sbin/nginx" # nginx啟動文件
prog=$(basename $nginx)
NGINX_CONF_FILE="/data/server/nginx/conf/nginx.conf" # 配置文件路徑
lockfile=/var/lock/subsys/nginx
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
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
保存
:wq對腳本添加可執(zhí)行權限
chmod +x /etc/init.d/nginx
添加nginx到自啟動服務
chkconfig --add nginx
設置開機啟動
chkconfig nginx on
開啟訪問端口
vi /etc/sysconfig/iptables
添加如下
-A INPUT –m state –state NEW –m tcp –p tcp –dport 80 –j ACCEPT
重啟防火墻以應用規(guī)則
/etc/init.d/iptables restart1
此后,執(zhí)行命令腳本即可,無需執(zhí)行原路徑的執(zhí)行文件
/etc/init.d/nginx start # 啟動nginx
/etc/init.d/nginx stop # 停止nginx
/etc/init.d/nginx restart # 重啟nginx
/etc/init.d/nginx reload # 重新加載配置文件
原操作命令
/data/server/nginx/sbin/nginx # start server
/data/server/nginx/sbin/nginx -s stop # fast shutdown
/data/server/nginx/sbin/nginx -s quit # graceful shutdown
/data/server/nginx/sbin/nginx -s reload # reloading the configuration file
/data/server/nginx/sbin/nginx -s reopen # reopening the log files
至此,nginx的安裝與最基本的配置已完成
configure過程可能出現(xiàn)的情況
缺少C編譯器,需要安裝gcc
運行安裝命令,yum install -y gcc
未安裝PCRE
運行安裝命令,yum install -y pcre pcre-devel
缺少安全庫
運行安裝命令,yum install -y openssl openssl-devel
分享題目:CentOS編譯安裝Nginx
本文地址:http://fisionsoft.com.cn/article/dhigdej.html


咨詢
建站咨詢
