在CentOS 7上安装最新版本的Nginx stable(通过官方软件仓库)

首先

使用公式存储库在CentOS7上安装最新的稳定版Nginx
原文:Nginx各种安装方法和EOL总结参考:nginx:Linux软件包

支持

如果使用这种方法进行引入,我认为它将得到支持,直到nginx的开发停止。
如果不指定特定版本,我认为始终会提供最新的稳定版本。

日志

仓库注册

# vi /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

[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

安装

# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

# yum install -y nginx which
... 略

nginx的启动/停止

# systemctl start nginx
# systemctl status -l nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-14 14:50:02 UTC; 4s ago
     Docs: http://nginx.org/en/docs/
  Process: 203 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 204 (nginx)
   CGroup: /docker/06d90e6c37f516e7cf512b23098bd7c5403966bc2c70bbf8f75391af2175faf2/system.slice/nginx.service
           tq204 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           mq205 nginx: worker process
           ? 204 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

Oct 14 14:50:02 06d90e6c37f5 systemd[1]: Starting nginx - high performance web server...
Oct 14 14:50:02 06d90e6c37f5 systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
Oct 14 14:50:02 06d90e6c37f5 systemd[1]: Started nginx - high performance web server.
# systemctl stop nginx
# systemctl status -l nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: http://nginx.org/en/docs/

Oct 14 14:50:02 06d90e6c37f5 systemd[1]: Starting nginx - high performance web server...
Oct 14 14:50:02 06d90e6c37f5 systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
Oct 14 14:50:02 06d90e6c37f5 systemd[1]: Started nginx - high performance web server.
Oct 14 14:50:19 06d90e6c37f5 systemd[1]: Stopping nginx - high performance web server...
Oct 14 14:50:19 06d90e6c37f5 systemd[1]: Stopped nginx - high performance web server.

自动启动/取消Nginx配置。

# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

# systemctl list-unit-files --type=service |grep nginx
nginx-debug.service                    disabled
nginx.service                          enabled
# systemctl disable nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.

# systemctl list-unit-files --type=service |grep nginx
nginx-debug.service                    disabled
nginx.service                          disabled

不同的确认

# which nginx
/usr/sbin/nginx

# nginx -v
nginx version: nginx/1.16.1

# yum info nginx
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
Installed Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.16.1
Release     : 1.el7.ngx
Size        : 2.7 M
Repo        : installed
From repo   : nginx-stable
Summary     : High performance web server
URL         : http://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.