1、安装依赖
yum install patch wget make gcc gcc-c++ gcc-gfortran kernel-devel ncurses ncurses-devel gd gd-devel libicu lua zlib-devel openssl-devel pcre-devel perl-IPC-Cmd -y
注:perl-IPC-Cmd 为openssl-quic中的依赖需求必须安装
2、下载源码包并解压
wget https://nginx.org/download/nginx-1.27.0.tar.gz
tar -xzf nginx-1.27.0.tar.gz
3、下载quicssl库依赖并解压
wget https://github.com/quictls/openssl/archive/refs/tags/openssl-3.1.5-quic1.tar.gz
tar -xzf openssl-3.1.5-quic1.tar.gz
4、进入nginx源码目录开始构建
cd nginx-1.27.0
5、配置构建参数
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v3_module --with-cc-opt=-I../openssl-openssl-3.1.5-quic1/include --with-ld-opt=-L../openssl-openssl-3.1.5-quic1/lib --with-openssl=../openssl-openssl-3.1.5-quic1
6、构建并且安装
make & make install
7、配置用户组
useradd -M nginx
8、创建缺失的目录
mkdir -p /var/cache/nginx/client_temp
mkdir -p /var/log/nginx
mkdir -p /usr/lib64/nginx/modules //此目录非必须,该目录为添加动态模块用途
9、配置服务并且设置开机启动
vi /usr/lib/systemd/system/nginx.service
将下面的内容复制粘贴上去:
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
[Install]
WantedBy=multi-user.target
10、执行重载命令
systemctl daemon-reload
11、配置开机启动
systemctl enable nginx
12、启动nginx服务
systemctl start nginx
13、查看nginx服务状态
systemctl status nginx
14、重启Nginx服务
systemctl restart nginx
15、关闭开机启动
systemctl disable nginx
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。