cent os nginx 部署

1.在安装Nginx之前,要确保已经安装了需要的软件:gcc、pcre-devel、zlib-devel、openssl-devel。如果没有安装,执行下面命令。

    yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

2、进入 /usr/local/文件夹

 cd /usr/local

3、下载nginx

wget https://nginx.org/download/nginx-1.18.0.tar.gz  

或者直接去官网下载:

https://nginx.org/en/download.html

选择合适的版本下载

4、解压nginx安装包

tar -zxvf   nginx-1.25.0.tar.gz

5、进入解压后文件夹

cd  nginx-1.25.0

6.配置安装参数

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

7.编译安装

make

make install

8.编译安装完成之后,进入/usr/local/nginx,查看是否安装成功

/usr/local/nginx/sbin/nginx  -t

 9.注册服务

touch /etc/init.d/nginx

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

赋予权限

chmod 777 /etc/init.d/nginx

添加服务

chkconfig -add nginx

启动服务

systemctl start/stop/restart nginx  

 

10.nginx 配置

vi /usr/local/nginx/conf/nginx.conf

 

11.关闭防火墙

systemctl stop firewalld.service

systemctl disable firewalld.service

 

posted @ 2023-08-07 11:29  赏花赏月赏秋香  阅读(59)  评论(0编辑  收藏  举报