手把手带你在Linux centos7环境下安装Nginx 包括https开机自启等

1.安装gcc,执行命令进行安装:

yum -y install gcc automake autoconf libtool make

2.安装pcre-devel :

yum install -y pcre pcre-devel

3.安装zlib :

yum install -y zlib zlib-devel

4.安装OpenSSL :

yum install -y openssl openssl-devel

5.进入Nginx压缩包所在目录:

cd /usr/local/nginx

6.解压:

tar -zxvf nginx-1.18.0.tar.gz

7.解压完成后,进入Nginx软件所在目录:

cd nginx-1.18.0

8.配置 支持HTTPS

./configure --prefix=/usr/local/nginx --with-http_ssl_module

10.编译:

make

11.安装:

make install

12.查看Nginx是否安装成功:

cd /usr/local/nginx/sbin/

./nginx -t

显示如下图,说明安装成功
在这里插入图片描述

13.关闭防火墙

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

不关闭也可以 防火墙自行打开nginx的端口

14.设置开机启动
① 在系统/etc/init.d/目录下创建nginx文件:

vi /etc/init.d/nginx

② 将以下内容添加到该文件中:

#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx server"
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

③ 保存退出后,设置文件的执行权限:

chmod a+x /etc/init.d/nginx

④ 将服务加入chkconfig管理列表:

chkconfig --add /etc/init.d/nginx

⑤ 设置终端模式开机启动:

chkconfig nginx on

⑥ 启动和停止、重载配置命令:

service nginx start #启动
service nginx stop #停止
service nginx reload #重载配置文件

测试是否启动成功:在浏览器输入:http://IP,出现下图界面,说明安装启动成功

curl http://127.0.0.1:80/

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值