1、使用 yum 直接安装 Nginx
[root@hexingxing ~]# yum install -y nginx
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Determining fastest mirrors
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.nwsuaf.edu.cn
No package nginx available.
错误:无须任何处理
## 系统不能直接 yum install nginx,判断可能 yum 源有问题
2、下载 Nginx 源
[root@hexingxing html]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
Retrieving http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
warning: /var/tmp/rpm-tmp.KcjpHW: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ########################################### [100%]
1:nginx-release-centos ########################################### [100%]
##下载成功
3、查看 Nginx 源是否下载成功
[root@hexingxing ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo nginx.repo
## 在/etc/yum.repos.d/ 存在 nginx.repo 文件,那么可以安装了,为了确认是否可安装,先查看下 Nginx 的软件信息
4、查看 Nginx 软件信息
[root@hexingxing html]# yum info nginx
已加载插件:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
nginx | 2.9 kB 00:00
nginx/primary_db | 15 kB 00:00
可安装的软件包
Name : nginx
Arch : x86_64
Version : 1.10.1
Release : 1.el6.ngx
Size : 821 k
Repo : nginx
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 的软件信息,说明已经可以安装了
5、安装 Nginx
[root@hexingxing ~]# yum install nginx
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
解决依赖关系
--> 执行事务检查
---> Package nginx.x86_64 0:1.10.1-1.el6.ngx will be 安装
--> 完成依赖关系计算
依赖关系解决
=================================================================================================================================================================================
软件包 架构 版本 仓库 大小
=================================================================================================================================================================================
正在安装:
nginx x86_64 1.10.1-1.el6.ngx nginx 821 k
事务概要
=================================================================================================================================================================================
Install 1 Package(s)
总下载量:821 k
Installed size: 2.1 M
确定吗?[y/N]:y
下载软件包:
nginx-1.10.1-1.el6.ngx.x86_64.rpm | 821 kB 00:23
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
正在安装 : nginx-1.10.1-1.el6.ngx.x86_64 1/1
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
----------------------------------------------------------------------
Verifying : nginx-1.10.1-1.el6.ngx.x86_64 1/1
已安装:
nginx.x86_64 0:1.10.1-1.el6.ngx
完毕!
##Nginx 安装完成
6、启动 Nginx
[root@hexingxing ~]# service nginx start
正在启动 nginx:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[失败]
##发现启动 Nginx 失败,根据以上错误信息,我发现可能是因为之前已安装并启动了 Apache,可能因此而报错,所以我现在停止 Apache 服务
6、停止 Apache
[root@hexingxing ~]# service httpd stop
停止 httpd: [确定]
##停止 Apache
7、启动 Nginx
[root@hexingxing ~]# service nginx start
正在启动 nginx: [确定]
##启动 Nginx 成功
8、访问服务器 IP
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
##访问服务器 IP 出现以上提示,说明 Nginx 已经安装成功并且可用,Nginx 的 Web 默认目录为 /usr/share/nginx/html/ ,可在此目录下放置网站文件,安装了 PHP 后可运行 PHP 网站。
到此,Nginx 已经安装成功。如果 Nginx 的 Web 页面不能访问可能还需要配置服务器的防火墙,配置防火墙和继续安装 MySQL 和 PHP ,可以参考何星星之前写的一篇《CentOS 6.8 配置 LAMP(Linux+Apache+PHP+MySQL)环境》。
0 条评论