1 Nginx鏡像庫添加
- Ngin鏡像庫文件添加
## 由於YUM中沒有Nginx鏡像庫文件 需要手動添加
vi /etc/yum.repos.d/nginx.repo
- Nginx鏡像庫內容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
- Nginx鏡像庫配置查看
yum list nginx
配置鏡像庫文件查看結果
Last metadata expiration check: 0:10:25 ago on Fri 06 Mar 2020 09:05:02 AM EST.
Installed Packages
nginx.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
2 安裝Nginx
- 查看可安裝Nginx版本
yum list |grep nginx
nginx.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-all-modules.noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-filesystem.noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-mod-http-image-filter.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-mod-http-perl.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-mod-http-xslt-filter.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-mod-mail.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-mod-stream.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 @AppStream
nginx-module-image-filter.x86_64 1:1.16.1-1.el8.ngx nginx
nginx-module-image-filter-debuginfo.x86_64 1:1.16.1-1.el8.ngx nginx
nginx-module-njs.x86_64 1:1.16.1.0.3.8-1.el8.ngx nginx
nginx-module-njs-debuginfo.x86_64 1:1.16.1.0.3.8-1.el8.ngx nginx
nginx-module-perl.x86_64 1:1.16.1-1.el8.ngx nginx
nginx-module-perl-debuginfo.x86_64 1:1.16.1-1.el8.ngx nginx
nginx-module-xslt.x86_64 1:1.16.1-1.el8.ngx nginx
nginx-module-xslt-debuginfo.x86_64 1:1.16.1-1.el8.ngx nginx
pcp-pmda-nginx.x86_64 4.3.2-2.el8 AppStream
- 安裝Nginx
## 安裝最新版本Nignx
yum -y install nginx
3 啓動Nginx
nginx
4 查看Nginx
- 命令行查看Nginx
curl 127.0.0.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Red Hat Enterprise Linux</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #fff;
color: #000;
font-size: 0.9em;
font-family: sans-serif,helvetica;
margin: 0;
padding: 0;
}
:link {
color: #c00;
}
:visited {
color: #c00;
}
a:hover {
color: #f50;
}
h1 {
text-align: center;
margin: 0;
padding: 0.6em 2em 0.4em;
background-color: #900;
color: #fff;
font-weight: normal;
font-size: 1.75em;
border-bottom: 2px solid #000;
}
h1 strong {
font-weight: bold;
font-size: 1.5em;
}
h2 {
text-align: center;
background-color: #900;
font-size: 1.1em;
font-weight: bold;
color: #fff;
margin: 0;
padding: 0.5em;
border-bottom: 2px solid #000;
}
hr {
display: none;
}
.content {
padding: 1em 5em;
}
.alert {
border: 2px solid #000;
}
img {
border: 2px solid #fff;
padding: 2px;
margin: 2px;
}
a:hover img {
border: 2px solid #294172;
}
.logos {
margin: 1em;
text-align: center;
}
/*]]>*/
</style>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Red Hat Enterprise Linux!</h1>
<div class="content">
<p>This page is used to test the proper operation of the
<strong>nginx</strong> HTTP server after it has been
installed. If you can read this page, it means that the
web server installed at this site is working
properly.</p>
<div class="alert">
<h2>Website Administrator</h2>
<div class="content">
<p>This is the default <tt>index.html</tt> page that
is distributed with <strong>nginx</strong> on
Red Hat Enterprise Linux. It is located in
<tt>/usr/share/nginx/html</tt>.</p>
<p>You should now put your content in a location of
your choice and edit the <tt>root</tt> configuration
directive in the <strong>nginx</strong>
configuration file
<tt>/etc/nginx/nginx.conf</tt>.</p>
<p>For information on Red Hat Enterprise Linux, please visit the <a href="http://www.redhat.com/">Red Hat, Inc. website</a>. The documentation for Red Hat Enterprise Linux is <a href="http://www.redhat.com/docs/manuals/enterprise/">available on the Red Hat, Inc. website</a>.</p>
</div>
</div>
<div class="logos">
<a href="http://nginx.net/"><img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" /></a>
<a href="http://www.redhat.com/"><img
src="poweredby.png"
alt="[ Powered by Red Hat Enterprise Linux ]"
width="88" height="31" /></a>
</div>
</div>
</body>
</html>
- 畫面查看Nginx
5 Nginx開機自啓動
- 添加
systemctl enable nginx
systemctl daemon-reload
- 移除
systemctl disable nginx
systemctl daemon-reload
6 其他
- nginx啓動/停止
systemctl start nginx
systemctl stop nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
- nginx啓動狀態
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-03-06 11:08:45 EST; 30min ago
Process: 928 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 902 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 897 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 935 (nginx)
Tasks: 2 (limit: 11499)
Memory: 12.3M
CGroup: /system.slice/nginx.service
├─935 nginx: master process /usr/sbin/nginx
└─936 nginx: worker process
Mar 06 11:08:45 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 06 11:08:45 localhost.localdomain nginx[902]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 06 11:08:45 localhost.localdomain nginx[902]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 06 11:08:45 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.