搭建 nginx
<h5>参考网址</h5>
<ul>
<li><a href="https://www.cnblogs.com/larryzq/p/11009045.html">https://www.cnblogs.com/larryzq/p/11009045.html</a></li>
<li><a href="https://www.cnblogs.com/opsprobe/p/10773582.html">https://www.cnblogs.com/opsprobe/p/10773582.html</a></li>
</ul>
<pre><code class="language-shell">less /etc/redhat-release # 查看系统版本
# CentOS Linux release 7.9.2009 (Core)</code></pre>
<h2>yum使用前期准备</h2>
<pre><code class="language-shell"># 查看 yum 版本
yum --version
# 查看已经安装的 yum 源,一般设置使用阿里云 yum 源
yum repolist
# 更新 yum
yum update -y</code></pre>
<h2>安装nginx</h2>
<h5>nginx安装官方文档说明</h5>
<ul>
<li><a href="http://nginx.org/en/linux_packages.html#RHEL-CentOS">http://nginx.org/en/linux_packages.html#RHEL-CentOS</a></li>
</ul>
<h5>前期准备</h5>
<pre><code class="language-shell"># 查看是否已经安装 nginx
whereis nginx
# 查看有是否有 nginx 安装包
yum serach nginx
# nginx 没有在 yum 库中自带,不能使用 yum install nginx 直接去安装
# 查看是否安装 yum 管理仓库及扩展包的工具 yum-utils
yum list installed | grep yum-utils
# 安装 yum-utils
yum install -y yum-utils</code></pre>
<h5>设置yum存储库</h5>
<pre><code class="language-shell">cd /etc/yum.repos.d
vim 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
# 或者使用简单方法添加 Nginx 到YUM源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 查看 nginx 是否成功添加到 yum 源中
yum search nginx</code></pre>
<h5>安装nginx</h5>
<pre><code class="language-shell"># 安装Nginx
yum install -y nginx
# 启动Nginx
systemctl start nginx.service
ps -aux | grep nginx
# 设置Nginx为开机启动
systemctl enable nginx.service
ip addr # ip 地址为 192.168.0.105</code></pre>
<h5>查看nginx是否安装成功</h5>
<ul>
<li>浏览器输入ip地址: 192.168.0.105,显示 nginx 默认页:Welcome to nginx!</li>
</ul>
<h2>Nginx配置信息</h2>
<pre><code class="language-shell">whereis nginx
# nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz</code></pre>
<h5>目录信息</h5>
<table>
<thead>
<tr>
<th>说明</th>
<th>目录</th>
</tr>
</thead>
<tbody>
<tr>
<td>网站文件存放默认目录</td>
<td>/usr/share/nginx/html</td>
</tr>
<tr>
<td>网站默认站点配置</td>
<td>/etc/nginx/conf.d/default.conf</td>
</tr>
<tr>
<td>自定义站点配置文件存放目录</td>
<td>/etc/nginx/conf.d/</td>
</tr>
<tr>
<td>全局配置</td>
<td>/etc/nginx/nginx.conf</td>
</tr>
</tbody>
</table>