Rocky Linux:编译安装nginx 1.24.0(Rocky Linux 9.1)

一,官网:

如图:

二,下载并解压

下载:

[root@img nginx]# wget http://nginx.org/download/nginx-1.24.0.tar.gz
解压:
[root@img nginx]# tar -zxvf nginx-1.24.0.tar.gz 

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/rocky-linux-bian-yi-an-zhuang-nginx-1-24-rocky-linux-9-1/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

三,安装

配置

#--prefix 指定安装路径

#--with-http_stub_status_module    允许查看nginx状态的模块

# --with-http_ssl_module     支持https的模块

[root@img nginx-1.24.0]# ./configure --prefix=/usr/local/soft/nginx-1.24.0 --with-http_stub_status_module --with-http_ssl_module
编译并安装
[root@img nginx-1.24.0]# make && make install  

四,configure时遇到报错的处理:

报错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决:
[root@img nginx-1.24.0]# dnf install pcre-devel

五,查看软件信息

1,查看版本
[root@img nginx-1.24.0]# /usr/local/soft/nginx-1.24.0/sbin/nginx -v
nginx version: nginx/1.24.0
2,查看编译参数
[root@img nginx-1.24.0]# /usr/local/soft/nginx-1.24.0/sbin/nginx -V
nginx version: nginx/1.24.0
built by gcc 11.3.1 20220421 (Red Hat 11.3.1-2) (GCC)
built with OpenSSL 3.0.1 14 Dec 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/soft/nginx-1.24.0 --with-http_stub_status_module --with-http_ssl_module

六,用systemctl管理nginx服务:

1,创建目录
[root@img nginx-1.24.0]# mkdir /web/logs/nginxlogs
[root@img nginx-1.24.0]# chmod 777 /web/logs/nginxlogs/
2,创建用户

#-g:指定所属的group

#-s:指定shell,因为它不需要登录,所以用/sbin/nologin

#-M:不创建home目录,因为它不需要登录

[root@img nginx-1.24.0]# groupadd nginx
[root@img nginx-1.24.0]# useradd -g nginx -s /sbin/nologin -M nginx
3,编辑配置文件:
[root@img nginx-1.24.0]# cd /usr/local/soft/nginx-1.24.0/conf/
[root@img conf]# vi nginx.conf
文件内容
指定运行nginx的用户和组
user  nginx nginx;
指定错误日志的路径
error_log   /web/logs/nginxlogs/error.log;
指定pid的路径
pid        logs/nginx.pid;
指定日志格式(去掉注释即可)
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for”';
指定访问日志的路径
access_log  /web/logs/nginxlogs/access.log  main;
 
4,创建service文件
[root@img nginx-1.24.0]# vi /usr/lib/systemd/system/nginx.service
文件内容
[Unit]
Description=nginx-The High-performance HTTP Server
After=network.target


[Service]
Type=forking
PIDFile=/usr/local/soft/nginx-1.24.0/logs/nginx.pid
ExecStartPre=/usr/local/soft/nginx-1.24.0/sbin/nginx -t -c /usr/local/soft/nginx-1.24.0/conf/nginx.conf
ExecStart=/usr/local/soft/nginx-1.24.0/sbin/nginx -c /usr/local/soft/nginx-1.24.0/conf/nginx.conf
ExecReload=/usr/local/soft/nginx-1.24.0/sbin/nginx -s reload
ExecStop=/usr/local/soft/nginx-1.24.0/sbin/nginx -s stop
PrivateTmp=true


[Install]
WantedBy=multi-user.target
5,重新加载服务文件
[root@img nginx-1.24.0]# systemctl daemon-reload

 

启动服务:
[root@img nginx-1.24.0]# systemctl start nginx
6,访问nginx服务,如图:
 

七,查看linux的版本:

[root@blog ~]# cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)

 

posted @ 2023-05-10 11:24  刘宏缔的架构森林  阅读(2122)  评论(1)    收藏  举报