在CentOS7上安装nginx
请参考以下网站:
https://www.rem-system.com/centos-nginx-inst/
$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
# firewall-cmd --add-service=http --permanent
success
# firewall-cmd --reload
success
# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
要安装nginx,需要添加nginx库存库。
检查当前的库存文件。
$ ls -s /etc/yum.repos.d/
total 48
4 CentOS-Base.repo 4 CentOS-Media.repo 4 epel.repo
4 CentOS-CR.repo 4 CentOS-Sources.repo 4 epel-testing.repo
4 CentOS-Debuginfo.repo 12 CentOS-Vault.repo
4 CentOS-fasttrack.repo 4 CentOS-x86_64-kernel.repo
将用于nginx的存储库文件添加到上述目录中。
添加Nginx的存储库文件。
# vi /etc/yum.repos.d/nginx.repo
#公式サイトを参考に以下を記述
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
我們將進行附加確認。
$ yum search nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* epel: ftp.iij.ad.jp
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
nginx | 2.9 kB 00:00
nginx/x86_64/primary_db | 186 kB 00:01
============================== N/S matched: nginx ==============================
collectd-nginx.x86_64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nginx-all-modules.noarch : A meta package that installs all available Nginx
: modules
nginx-debug.x86_64 : debug version of nginx
nginx-debuginfo.x86_64 : Debug information for package nginx
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules
nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
nginx-module-geoip-debuginfo.x86_64 : Debug information for package
: nginx-module-geoip
nginx-module-image-filter.x86_64 : nginx image filter dynamic module
nginx-module-image-filter-debuginfo.x86_64 : Debug information for package
: nginx-module-image-filter
nginx-module-njs.x86_64 : nginx njs dynamic modules
nginx-module-njs-debuginfo.x86_64 : Debug information for package
: nginx-module-njs
nginx-module-perl.x86_64 : nginx Perl dynamic module
nginx-module-perl-debuginfo.x86_64 : Debug information for package
: nginx-module-perl
nginx-module-xslt.x86_64 : nginx xslt dynamic module
nginx-module-xslt-debuginfo.x86_64 : Debug information for package
: nginx-module-xslt
nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
owncloud-nginx.noarch : Nginx integration for ownCloud
pagure-web-nginx.noarch : Nginx configuration for Pagure
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx
: Webserver
python2-certbot-nginx.noarch : The nginx plugin for certbot
sympa-nginx.x86_64 : Sympa with nginx
nginx.x86_64 : High performance web server
unit.x86_64 : NGINX Unit
unit-devel.x86_64 : NGINX Unit (development tools)
Name and summary matches only, use "search all" for everything.
顺便提一句,安装nginx所需的软件包是 nginx.x86_64: 高性能网页服务器。
nginxのインストール
首先,我们将确认nginx软件包的信息。
$ yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* epel: ftp.iij.ad.jp
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
Installed Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.16.1
Release : 3.el7
Size : 1.6 M
Repo : installed
From repo : epel
Summary : A high performance web server and reverse proxy server
URL : http://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.
Available Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.19.5
Release : 1.el7.ngx
Size : 788 k
Repo : nginx/x86_64
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.
ではnginxパッケージをインストールします。
#-yオプションをつけることでインストール時の確認応答を省ける(知らなかった)
# yum -y install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.7 kB 00:00
* base: ty1.mirror.newmediaexpress.com
* epel: ftp.iij.ad.jp
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
nginx | 2.9 kB 00:00
updates | 2.9 kB 00:00
nginx/x86_64/primary_db | 186 kB 00:01
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.16.1-3.el7 will be updated
---> Package nginx.x86_64 1:1.19.5-1.el7.ngx will be an update
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
nginx x86_64 1:1.19.5-1.el7.ngx nginx 788 k
Transaction Summary
================================================================================
Upgrade 1 Package
Total download size: 788 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
nginx-1.19.5-1.el7.ngx.x86_64.rpm | 788 kB 00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:nginx-1.19.5-1.el7.ngx.x86_64 1/2
Cleanup : 1:nginx-1.16.1-3.el7.x86_64 2/2
Verifying : 1:nginx-1.19.5-1.el7.ngx.x86_64 1/2
Verifying : 1:nginx-1.16.1-3.el7.x86_64 2/2
Updated:
nginx.x86_64 1:1.19.5-1.el7.ngx
确认已安装的nginx软件包
$ yum list installed | grep nginx
nginx.x86_64 1:1.19.5-1.el7.ngx @nginx
已经安装了。
启动nginx
$ systemctl start nginx
#起動しているかの確認
$ systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2020-12-13 09:36:54 JST; 17s ago
Docs: http://nginx.org/en/docs/
Process: 30579 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 30580 (nginx)
CGroup: /system.slice/nginx.service
tq30580 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx....
mq30581 nginx: worker process
Dec 13 09:36:54 f5les1se systemd[1]: Starting nginx - high performance web .....
Dec 13 09:36:54 f5les1se systemd[1]: Can't open PID file /var/run/nginx.pid...ry
Dec 13 09:36:54 f5les1se systemd[1]: Started nginx - high performance web s...r.
Hint: Some lines were ellipsized, use -l to show in full.
由于正在运行,所以正常工作。
似乎还有其他方法可以使用ps命令来确认正在运行的进程。
$ ps -aux | grep nginx
root 30580 0.0 0.0 46492 972 ? Ss 09:36 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 30581 0.0 0.1 46884 1600 ? S 09:36 0:00 nginx: worker process
admin 30602 0.0 0.0 112812 972 pts/0 S+ 09:39 0:00 grep --color=auto nginx
Nginx的自动启动设置
サーボの再起動時などに、nginxが自動的に起動するように設定しておきます。
ここでもsystemctlコマンドを使います。
#centOSでenableは自動起動を意味する
$ systemctl enable nginx
自動起動設定されているかの確認も念のためしておきます。
$ systemctl is-enabled nginx
enabled
由於已啟用,所以設定已完成。
在网页上进行确认
使用以上步骤,应该能够在提供的nginx软件包中显示“网页。
在个人的网络浏览器中搜索安装了nginx服务器的IP地址。
例如:http://140.00.00.00。
如果出现上述的画面显示,表示设置已经正常完成。