使用 yum安装 nginx 的官方预编译包安装
1. 配置 yum 仓库(CentOS/RHEL):
创建 /etc/yum.repos.d/nginx.repo 文件,内容如下:
<code>[nginx] name=nginx repo <span># Stable version</span><span>#baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/</span><span># Mainline version</span><span>#baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/</span>baseurl=http:<span>//nginx.org/packages/centos/7/$basearch/</span> gpgcheck=<span>0</span> enabled=<span>1</span></code>
说明:(推荐 Stable version)
“OS”: 可以是 “centos” 或 “rhel”,根据 Linux 发行版本决定
“OSRELEASE”: 可以是 5/6/7; 分别对应 5.x;6.x;7.x 版本
2. 安装签名(RPM 包管理使用了数字签名进行验证包的合法性)
在 nginx 官网下面地址中搜索:nginx signing key,找到签名文件地址
http://nginx.org/en/linux_packages.html#stable
<code>user> cd user> wget <span>http</span>://nginx.org/<span>keys</span>/nginx_signing.key user> sudo rpm <span>--import nginx_signing.key</span></code>
3. 验证 nginx 的配置成功
<code>user> yum search nginx 找到如下项目说明配置成功 <span>nginx.x86_64 </span>: High performance web server</code>
4. 安装 nginx
<code>user> yum <span>install</span> nginx</code>
安装包下载仅 372KB
5. 启动/停止nginx服务
**user> sudo systemctl start nginx
user> sudo systemctl stop nginx
user> sudo systemctl restart nginx
user> ps -ef | grep nginx
user> sudo kill -QUIT
<code><span>#</span><span>开放</span><span>80</span><span>TCP</span><span>端口</span><span>user</span>> <span>sudo</span><span>firewall</span><span>-</span><span>cmd</span><span>-</span><span>-</span><span>z/span><span>-</span><span>-</span><span>add</span><span>-</span><span>port=80/tcp</span><span>-</span><span>-</span><span>permanent</span><span>user</span>> <span>sudo</span><span>firewall</span><span>-</span><span>cmd</span><span>-</span><span>-</span><span>reload</span></span></code>
6. 配置
默认的主配置文件为:
/etc/nginx/nginx.conf
此文件默认包含了 /etc/nginx/conf.d/ 目录下的 *.conf 文件
而服务相关的 server {} 段在 conf.d/default.conf 文件中。
7. 自启动
用如下命令设置:
<code>user> <span>sudo</span> systemctl enable nginx</code>
8. 关闭自启动
<code>user> <span>sudo</span> systemctl disable nginx</code>
以上就介绍了在 CentOS7 下用 yum 安装 nginx,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。