一,使用yum命令安装
1.检查是已经安装
命令:nginx -V
没有安装时显示如下
2.首先了解nginx不在centos的官方软件源下面,所以不可以直接使用
yun install nginx
进行安装。
需要先执行:yum install epel-release
选择 y 进行安装
结尾出现下图说明上面操作完成
3.下面开始安装nginx
使用命令:yum install nginx
如果出现下面问题
是因为/etc/yum.repos.d/epel.repo配置文件中源地址没有生效
vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
修改成:
注意是第三行的https修改成了http
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
…
…省略处
…
再次执行yum install nginx
执行 y
继续执行 y
nginx -V
查看版本
安装完成!
启动nginx (注意:如果centos版本是7的,需要在安装目录使用启动命令)
命令:nginx
查看ps -ef|grep nginx
==========================================
centos6.5关闭防火墙命令
1.永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2.即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
查找配置文件命令
nginx -t
nginx默认是安装在 /etc 下的
二,使用源码安装
1.上传并解压该文件
2.可以自己定义安装位置和nginx服务位置
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
3.编译和安装
make && make install
(我自定义服务位置出了问题,不能直接用nginx命令启动,所以我启动如下)
成功:
停止:
肯能是需要重启一下,因为我第二天打开后就可以直接用ngixn命令启动了
可参考:
https://itaken.github.io/post/2017/09/14/nginx%E5%AE%89%E8%A3%85.html