赞
踩
1.官方网站查询方法
http://nginx.org,选择右侧:“documentation”,进入后点击上方:“Installing nginx”,新页面选择“Installation on Linux”中的“For Linux, nginx packages from nginx.org can be used”,点击最终页面中的“RHEL/CentOS”,网址为:
http://nginx.org/en/linux_packages.html#RHEL-CentOS
2. 建仓库源文件( yum repository), 内容如下:
vim /etc/yum.repos.d/nginx.repo
输入以下内容。
- [nginx-stable]
- name=nginx stable repo
- baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
- gpgcheck=1
- enabled=1
- gpgkey=https://nginx.org/keys/nginx_signing.key
- module_hotfixes=true
-
- [nginx-mainline]
- name=nginx mainline repo
- baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=https://nginx.org/keys/nginx_signing.key
- module_hotfixes=true
3.切换使用mainline版本,禁用stable版本
- yum-config-manager --enable nginx-mainline
- yum-config-manager --disable nginx-stable
yum install -y nginx
1. 启动服务
- systemctl start nginx.service # 启动服务
- systemctl status nginx.service # 查看服务状态
2.设置开机运行
systemctl enable nginx.service
将Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
注:/usr/lib/systemd/system/的.service文件都是自启动的。
3.其他命令
# 关闭服务
systemctl stop nginx.service
# 重启服务
systemctl restart nginx.service
- #查看nginx服务
- ps -ef | grep nginx
- ps aux | grep nginx
- #查看服务端口情况
- netstat -tunlp
编译nginx源代码包,可平滑升级版本。
1.安装依赖程序
yum install pcre-devel libxml2-devel libxslt-devel gd-devel gperftools-devel perl-devel perl-ExtUtils-Embed
点击链接,查看 openssl安装教程
按照第一点内容事先安装好openssl3.0以上版本的编译环境(1.1.1不需要),再安装第二点内容下载解压openssl源代码包。
2.下载解压源代码包
进入官方网站http://nginx.org,点击右侧的“download”,进入下载界面,选择“Stable version”中的最新版本,当前稳定版的版本为1.22.0。
- wget http://nginx.org/download/nginx-1.22.0.tar.gz
- tar -zxvf nginx-1.22.0.tar.gz
3.查询当前版本nginx的原编译参数
nginx -V
复制 configure arguments:后面的参数,作为下一步的编译参数
[root@VM-0-6-centos ~]# nginx -V
nginx version: nginx/1.23.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
在原编译参数后添加以下参数,其中--with-openssl后面指定openssl的源代码目录,--with-cc后面指定当前系统内最新的gcc可执行文件,不指定则使用旧版本gcc进行编译。
--with-openssl=/root/openssl-3.0.5 --with-cc=/usr/local/gcc-11.2.0/bin/gcc
4.停止nginx服务
systemctl stop nginx.service
5.编译
- cd nginx-1.22.0
- /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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-openssl=/root/openssl-3.0.5 --with-cc=/usr/local/gcc-11.2.0/bin/gcc
- make -j2
- systemctl stop nginx.service
- make install
- cd ..
-
6.查看版本号
- systemctl start nginx.service
- nginx -V
[root@VM-0-15-centos ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 11.2.0 (GCC)
built with OpenSSL 3.0.5 5 Jul 2022
TLS SNI support enabled
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。