centos编译安装Nginx
阳东ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信: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过程可能出现的情况,见文章最尾)
./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; # 目前只放静态页,所以不需要改
}
创建nginx系统服务脚本
vi /etc/init.d/nginx
填入如下内容
#!/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对脚本添加可执行权限
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
重启防火墙以应用规则
/etc/init.d/iptables restart1
此后,执行命令脚本即可,无需执行原路径的执行文件
/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过程可能出现的情况
缺少C编译器,需要安装gcc
运行安装命令,yum install -y gcc
未安装PCRE
运行安装命令,yum install -y pcre pcre-devel
缺少安全库
运行安装命令,yum install -y openssl openssl-devel
网站名称:CentOS编译安装Nginx
URL标题:http://www.stwzsj.com/qtweb/news32/16582.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联