[root@nginx data]# tar -zxvf pcre-8.40.tar.gz
[root@nginx data]# cd pcre-8.40/[root@nginx pcre-8.40]# ./configure --prefix=/data/unit/pcre
[root@nginx pcre-8.40]# make && make install
第二步:安装zlib
[root@nginx data]# tar -zxvf zlib-1.3.1.tar.gz
[root@nginx data]# cd zlib-1.3.1/[root@nginx zlib-1.3.1]# ./configure --prefix=/data/unit/zlib
[root@nginx zlib-1.3.1]# make && make install
第三步:安装openssl
[root@nginx data]# tar -zxvf openssl-3.2.1.tar.gz
[root@nginx data]# cd openssl-3.2.1/[root@nginx openssl-3.2.1]# ./config --prefix=/data/unit/openssl --shared
[root@nginx openssl-3.2.1]# make && make install
# 出现安装失败问题
[root@nginx openssl-3.2.1]# ./config --prefix=/data/unit/openssl --shared
Can't locate IPC/Cmd.pm in @INC(@INC contains:/data/openssl-3.2.1/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 ./data/openssl-3.2.1/external/perl/Text-Template-1.56/lib) at /data/openssl-3.2.1/util/perl/OpenSSL/config.pm line 19.
BEGIN failed--compilation aborted at /data/openssl-3.2.1/util/perl/OpenSSL/config.pm line 19.
Compilation failed in require at /data/openssl-3.2.1/Configure line 23.
BEGIN failed--compilation aborted at /data/openssl-3.2.1/Configure line 23.
# 解决方法
[root@nginx openssl-3.2.1]# yum install perl-IPC-Cmd
第四步:安装nginx
[root@nginx data]# tar -zxvf nginx-1.24.0.tar.gz
[root@nginx data]# cd nginx-1.24.0/[root@nginx nginx-1.24.0]# ./configure --prefix=/data/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-pcre=/data/pcre-8.40 \
--with-zlib=/data/zlib-1.3.1 \
--with-openssl=/data/openssl-3.2.1 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_gzip_static_module
[root@nginx ~]# cd /data/nginx/sbin/[root@nginx sbin]# ./nginx
# 查看结果
[root@nginx sbin]# curl 127.0.0.1:80<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>
html { color-scheme: light dark;}
body { width:35em; margin:0auto;
font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>
启动方式
[root@nginx ~]# cd /data/nginx/sbin/./nginx # 启动服务
./nginx -s reload # 重新载入配置文件
./nginx -s reopen # 重启 Nginx
./nginx -s stop # 停止 Nginx
-----------------------------------------------------------------------------------
# 添加启动文件即可通过systemctl命令来启动nginx
[root@bogon conf]# vi /lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/data/nginx/logs/nginx.pid
ExecStartPre=/data/nginx/sbin/nginx -t
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 重载systemctl服务
[root@nginx sbin]# systemctl daemon-reload
-----------------------------------------------------------------------------------
# 检查配置文件
[root@nginx nginx]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful