-、查看当前版本
# /opt/rh/rh-nginx116/root/usr/sbin/nginx -v
nginx version: nginx/1.16.1
二、准备依赖的文件包
# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# tar zxvf pcre-8.35.tar.gz -C /usr/local/src/
# cd /usr/local/src/pcre-8.35
[pcre-8.35]# ./configure
[pcre-8.35]# make
[pcre-8.35]# make install
make install-am
make[1]: Entering directory `/usr/local/src/pcre-8.35'
make[2]: Entering directory `/usr/local/src/pcre-8.35'
/bin/mkdir -p '/usr/local/lib'
/bin/sh ./libtool --mode=install /bin/install -c libpcre.la libpcreposix.la libpcrecpp.la '/usr/local/lib'
....
make[3]: Leaving directory `/usr/local/src/pcre-8.35'
make[2]: Leaving directory `/usr/local/src/pcre-8.35'
make[1]: Leaving directory `/usr/local/src/pcre-8.35'
三、编译安装nginx-1.22.1
# tar zxvf nginx-1.22.1.tar.gz
# cd nginx-1.22.1
[nginx-1.22.1]# ./configure --prefix=/opt/rh/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
checking for OS
+ Linux 3.10.0-862.2.3.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
...
Configuration summary
+ using PCRE library: /usr/local/src/pcre-8.35
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/opt/rh/nginx"
nginx binary file: "/opt/rh/nginx/sbin/nginx"
nginx modules path: "/opt/rh/nginx/modules"
nginx configuration prefix: "/opt/rh/nginx/conf"
nginx configuration file: "/opt/rh/nginx/conf/nginx.conf"
nginx pid file: "/opt/rh/nginx/logs/nginx.pid"
nginx error log file: "/opt/rh/nginx/logs/error.log"
nginx http access log file: "/opt/rh/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@xtjdbaelk01 nginx-1.22.1]# make
make -f objs/Makefile
make[1]: Entering directory `/home/dbadmin/nginx-1.22.1'
cd /usr/local/src/pcre-8.35 \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared
make[2]: Entering directory `/usr/local/src/pcre-8.35'
rm -f pcretest pcregrep
.....
objs/ngx_modules.o \
-ldl -lpthread -lcrypt /usr/local/src/pcre-8.35/.libs/libpcre.a -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/opt/rh/nginx|" \
-e "s|%%PID_PATH%%|/opt/rh/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/opt/rh/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/opt/rh/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/dbadmin/nginx-1.22.1'
[nginx-1.22.1]# make install
make -f objs/Makefile install
make[1]: Entering directory `/home/dbadmin/nginx-1.22.1'
...
test -f '/opt/rh/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/opt/rh/nginx/conf/nginx.conf'
cp conf/nginx.conf '/opt/rh/nginx/conf/nginx.conf.default'
test -d '/opt/rh/nginx/logs' \
|| mkdir -p '/opt/rh/nginx/logs'
test -d '/opt/rh/nginx/logs' \
|| mkdir -p '/opt/rh/nginx/logs'
test -d '/opt/rh/nginx/html' \
|| cp -R html '/opt/rh/nginx'
test -d '/opt/rh/nginx/logs' \
|| mkdir -p '/opt/rh/nginx/logs'
make[1]: Leaving directory `/home/dbadmin/nginx-1.22.1'
五、修改配置文件
# cd ..
# mkdir /opt/rh/nginx/conf.d
# cp /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf /opt/rh/nginx/conf.d
# cp /etc/opt/rh/rh-nginx116/nginx/nginx.conf /opt/rh/nginx/conf
# vi /opt/rh/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
error_log /opt/rh/nginx/logs/error.log;
pid /opt/rh/nginx/nginx.pid;
# Load dynamic modules. See /opt/rh/rh-nginx116/root/usr/share/doc/README.dynamic.
# include /opt/rh/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /opt/rh/nginx/logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /opt/rh/nginx/conf/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/rh/nginx/conf.d/*.conf;
# vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/opt/rh/nginx/sbin/nginx
ExecReload=/opt/rh/nginx/sbin/nginx -s reload
ExecStop=/opt/rh/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# systemctl enable nginx
# systemctl daemon-reload
# systemctl stop rh-nginx116-nginx
# systemctl start nginx
# systemctl status nginx
● nginx.service - nginx service
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2023-03-23 14:05:21 CST; 4s ago
Process: 522 ExecStart=/opt/rh/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 523 (nginx)
CGroup: /system.slice/nginx.service
├─523 nginx: master process /opt/rh/nginx/sbin/nginx
├─524 nginx: worker process
├─525 nginx: worker process
├─526 nginx: worker process
├─527 nginx: worker process
├─529 nginx: worker process
├─530 nginx: worker process
├─531 nginx: worker process
└─532 nginx: worker process
Mar 23 14:05:21 xtjdbaelk01 systemd[1]: Starting nginx service...
Mar 23 14:05:21 xtjdbaelk01 systemd[1]: Started nginx service.
--禁用原版本
# systemctl disable rh-nginx116-nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/rh-nginx116-nginx.service.
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




