我使用centos7X64最小化安装
CentOS-7-x86_64-Minimal-1708
挂在github上的个人博客:由hexo强力驱动 个人博客
1.配置防火墙:
关闭防火墙和加入放行端口二选一
1.1 直接关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]#
1.2 加入放行端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload #刷新防火墙 使其生效
firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
success
[root@localhost ~]# firewall-cmd --reload #刷新防火墙 使其生效
success
[root@localhost ~]# firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
80/tcp
[root@localhost ~]#
2.安装wget
yum -y install wget
3.安装nginx 编译环境
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
4.安装nginx
官方查看最新稳定版本 nginx1.12.2官网链接直达
我现在最新稳定版本是:nginx-1.12.2
wget -c https://nginx.org/download/nginx-1.12.2.tar.gz
5.解压
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
6.配置nginx
./configure
7.编译安装
make
make install
8.启动、停止、重启nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s reload #重新加载配置文件
./nginx -s quit #:推荐 待nginx进程处理任务完毕进行停止
./nginx -s stop #:先查出nginx进程id再使用kill命令强制杀掉进程。
9.查询nginx进程:
ps aux|grep nginx
10.开机自启动
在rc.local增加启动代码就可以了。
vi /etc/rc.local
底部增加一行:
/usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 /etc/rc.local