目录

一.源码安装nginx

1.配置源(之前博客有讲RHEL8配置本地镜像源和国内镜像源-CSDN博客)

2.进入/usr/local/src/目录下,使用wget将nginx源码安装在该目录之下

3.使用tar进行解压缩,进入nginx-1.20.2/目录

4.安装满足nginx运行条件的配置文件

5.执行configure脚本生成编译配置文件Makefile

6.安装make

7.测试nginx

二.编写systemd单元文件管理nginx服务

1.首先必须要停止nginx服务

2.在/etc/systemd/system/或者/usr/lib/systemd/system/目录下创建一个nginx.service文本文件

3.使用systemctl daemon-reload命令重载配置

4.测试

一.源码安装nginx

1.配置源(之前博客有讲RHEL8配置本地镜像源和国内镜像源-CSDN博客)

2.进入/usr/local/src/目录下,使用wget将nginx源码安装在该目录之下

(建议安装nginx1.20版本及以上,本例为1.20.2)

cd /usr/local/src/

 wget http://nginx.org/download/nginx-1.20.2.tar.gz

3.使用tar进行解压缩,进入nginx-1.20.2/目录

 tar -xf nginx-1.20.2.tar.gz

 cd nginx-1.20.2/

4.安装满足nginx运行条件的配置文件

gcc-c++        编译部分

yum install -y gcc gcc-c++

PCRE           正则表达式处理部分

yum install -y pcre-devel

OpenSSL     安全通信部分

 yum install -y openssl-devel

5.执行configure脚本生成编译配置文件Makefile

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

6.安装make

yum install -y make

执行命令make编译源代码,执行make install安装软件

make && make install

7.测试nginx

如果当前有Apache服务应该使其停下来以免产生冲突

systemctl stop httpd.service

还需关闭RHEL8的防火墙服务以便于可以访问nginx

systemctl stop firewalld.service

systemctl status firewalld.service

启动ngnix

/usr/local/nginx/sbin/nginx

使用浏览器进行访问(本例ip为10.0.0.8实际ip已自己虚拟机ip为准)

二.编写systemd单元文件管理nginx服务

1.首先必须要停止nginx服务

不然使用systemctl启动nginx服务时会出现如下错误

使用/usr/local/nginx/sbin/nginx -s stop停止nginx服务(可通过浏览器查看是否停止)

2.在/etc/systemd/system/或者/usr/lib/systemd/system/目录下创建一个nginx.service文本文件

编辑该文本文件(本例在/etc/systemd/system/目录下)

编辑内容如下

[Unit]  

Description=The NGINX HTTP and reverse proxy server  

After=network.target remote-fs.target nss-lookup.target  

[Service]  

Type=forking  

PIDFile=/usr/local/nginx/logs/nginx.pid  

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf  

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  

ExecReload=/bin/kill -s HUP $MAINPID  

ExecStop=/bin/kill -s QUIT $MAINPID  

PrivateTmp=true  

[Install]  

WantedBy=multi-user.target

保存退出

3.使用systemctl daemon-reload命令重载配置

4.测试

使用systemctl start nginx开启nginx

使用systemctl stop nginx关闭nginx

到此,配置完成

推荐链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: