企业级WEB服务Nginx安装

企业级WEB服务Nginx安装

1. Nginx版本和安装方式

  • Mainline version 主要开发版本,一般为奇数版本号,比如1.19
  • Stable version 当前最新稳定版,一般为偶数版本,如:1.20
  • Legacy versions 旧的稳定版,一般为偶数版本,如:1.18

Nginx安装可以使用yum或源码安装,但是推荐使用源码编译安装

  • yum的版本比较旧
  • 编译安装可以更方便自定义相关路径
  • 使用源码编译可以自定义相关功能,更方便业务的上的使用

2. 基于yum安装Nginx

2.1 查看当前系统中的Nginx版本

# Rocky Linux 9
[root@Rocky9 ~]# dnf info nginx
Last metadata expiration check: 2:51:40 ago on Fri 10 May 2024 12:57:53 PM CST.
Available Packages
Name         : nginx
Epoch        : 1
Version      : 1.20.1
Release      : 14.el9_2.1
Architecture : x86_64
Size         : 36 k
Source       : nginx-1.20.1-14.el9_2.1.src.rpm
Repository   : appstream
Summary      : A high performance web server and reverse proxy server
URL          : https://nginx.org
License      : BSD
Description  : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
             : IMAP protocols, with a strong focus on high concurrency, performance and low
             : memory usage.

[root@Rocky9 ~]#

# CentOS7 需提前配置好epel源
[root@localhost ~]#yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.aliyun.com
Available Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.20.1
Release     : 10.el7
Size        : 588 k
Repo        : epel/7/x86_64
Summary     : A high performance web server and reverse proxy server
URL         : https://nginx.org
License     : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
            : IMAP protocols, with a strong focus on high concurrency, performance and low
            : memory usage.

[root@localhost ~]#
# 我这里放到这里了
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
        https://mirrors.cloud.tencent.com/epel/$releasever/$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7

可以看到这些都比较旧,查看官方版本

image-20240510155409672

2.2 官方包源安装最新版本 nginx

系统和EPEL源的中nignx版本较旧,可以安装官方源的最新版本

官方包链接:

https://nginx.org/en/linux_packages.html

官方yum源连接

https://nginx.org/en/linux_packages.html#RHEL

配置官方yum源

[root@Rocky9 ~]# 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

# yum列出所有版本
[root@Rocky9 ~]# yum list --showduplicates nginx
Last metadata expiration check: 0:01:25 ago on Fri 10 May 2024 04:07:30 PM CST.
Available Packages
nginx.x86_64                                               1:1.20.1-14.el9_2.1                                                appstream
nginx.x86_64                                               1:1.20.2-1.el9.ngx                                                 nginx-stable
nginx.x86_64                                               1:1.22.0-1.el9.ngx                                                 nginx-stable
nginx.x86_64                                               1:1.22.1-1.el9.ngx                                                 nginx-stable
nginx.x86_64                                               1:1.24.0-1.el9.ngx                                                 nginx-stable
nginx.x86_64                                               1:1.26.0-1.el9.ngx                                                 nginx-stable
[root@Rocky9 ~]#

#查看版本信息
[root@Rocky9 ~]# dnf info nginx
Last metadata expiration check: 0:15:08 ago on Fri 10 May 2024 04:07:30 PM CST.
Available Packages
Name         : nginx
Epoch        : 1
Version      : 1.26.0
Release      : 1.el9.ngx
Architecture : x86_64
Size         : 995 k
Source       : nginx-1.26.0-1.el9.ngx.src.rpm
Repository   : nginx-stable
Summary      : High performance web server
URL          : https://nginx.org/
License      : 2-clause BSD-like license
Description  : nginx [engine x] is an HTTP and reverse proxy server, as well as
             : a mail proxy server.

[root@Rocky9 ~]# dnf -y install nginx

2.3 检查安装

查看Nginx安装包信息

[root@Rocky9 ~]# rpm -q nginx
nginx-1.26.0-1.el9.ngx.x86_64
[root@Rocky9 ~]# rpm -qi nginx
Name        : nginx
Epoch       : 1
Version     : 1.26.0
Release     : 1.el9.ngx
Architecture: x86_64
Install Date: Fri 10 May 2024 04:24:28 PM CST
Group       : System Environment/Daemons
Size        : 3511437
License     : 2-clause BSD-like license
Signature   : RSA/SHA256, Wed 24 Apr 2024 03:09:17 AM CST, Key ID abf5bd827bd9bf62
Source RPM  : nginx-1.26.0-1.el9.ngx.src.rpm
Build Date  : Wed 24 Apr 2024 02:25:42 AM CST
Build Host  : ip-10-1-17-66.eu-central-1.compute.internal
Vendor      : NGINX Packaging <nginx-packaging@f5.com>
URL         : https://nginx.org/
Summary     : High performance web server
Description :
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.
[root@Rocky9 ~]#

# 查看相关文件列表
[root@Rocky9 ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/usr/lib/.build-id
/usr/lib/.build-id/52
/usr/lib/.build-id/52/145ff3b622c4ce68927371a3c1c03f2b74eebe
/usr/lib/.build-id/75
/usr/lib/.build-id/75/43f6f2a6666b01d673a74132d0fe256c90c306
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.26.0
/usr/share/doc/nginx-1.26.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
[root@Rocky9 ~]#

# 查看版本
[root@Rocky9 ~]# nginx -v
nginx version: nginx/1.26.0
# 查看编译参数
[root@Rocky9 ~]# nginx -V
nginx version: nginx/1.26.0
built by gcc 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
built with OpenSSL 3.0.7 1 Nov 2022
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-http_v3_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 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
[root@Rocky9 ~]#

2.4 nginx程序用法帮助

使用安装完成的二进制文件nginx

[root@Rocky9 ~]# nginx -h
nginx version: nginx/1.26.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
             [-e filename] [-c filename] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit	#显示版本
  -V            : show version and configure options then exit	# 显示编译参数
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing	# 静默模式
  -s signal     : send signal to a master process: stop, quit, reopen, reload	# 发送信号,reload信号会生成新的worker,但master不会重新生成
  -p prefix     : set prefix path (default: /etc/nginx/)	# 指定Nginx 目录
  -e filename   : set error log file (default: /var/log/nginx/error.log)	# 日志文件路径
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf) # 配置文件路径
  -g directives : set global directives out of configuration file # 设置全局指令,注意和配置文件不要同时配置,否则冲突

[root@Rocky9 ~]#

2.5 验证Nginx

# 检查nginx语法是否正确
[root@Rocky9 ~]<

相关推荐

  1. Ubuntu安装WordPress并使用Nginx作为Web服务器

    2024-05-14 09:52:04       58 阅读
  2. nginx-----web服务器

    2024-05-14 09:52:04       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-14 09:52:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-14 09:52:04       101 阅读
  3. 在Django里面运行非项目文件

    2024-05-14 09:52:04       82 阅读
  4. Python语言-面向对象

    2024-05-14 09:52:04       91 阅读

热门阅读

  1. python常见数据的存取

    2024-05-14 09:52:04       27 阅读
  2. C++中匿名对象介绍及使用场景详解

    2024-05-14 09:52:04       33 阅读
  3. 超级好用的C++实用库之日志类

    2024-05-14 09:52:04       36 阅读
  4. 如何不用额外变量交换两个数

    2024-05-14 09:52:04       33 阅读
  5. 专访 Staynex 创始人 Yuen Wong:酒店行业的变革者

    2024-05-14 09:52:04       29 阅读
  6. 电商秒杀系统-案例04-redis下的session控制

    2024-05-14 09:52:04       37 阅读
  7. 100条常见的c语言bug汇总上篇3

    2024-05-14 09:52:04       36 阅读
  8. vue项目通过点击文字上传html文件,查看html文件

    2024-05-14 09:52:04       38 阅读
  9. K8S集群Etcd数据备份/恢复

    2024-05-14 09:52:04       29 阅读