环境:
linux版本:CentOS7 64位
【yum 安装最新版nginx:https://www.cnblogs.com/xxoome/p/7256214.html】
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
nginx下载地址:https://nginx.org/download/
创建一个文件夹方便管理
mkdir software
下载“ nginx-1.12.2.tar.gz”,移动到/root/software下。

安装: 解压 tar -zxvf nginx-1.12.2.tar.gz 进入nginx目录 重命名 mv nginx-1.12.2 nginx 切换到 cd nginx
配置 ./configure --prefix=/usr/local/nginx 安装 # make make make install
OK,现在可以执行make 了。

执行make、make install命令
测试是否安装成功
# cd到刚才配置的安装目录/usr/loca/nginx/
./sbin/nginx -t
正常情况的信息输出:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动nginx
cd /usr/local/nginx/sbin ./nginx //启动nginx
Nginx默认访问端口80,启动后需要确定一下是否可以用。
因为我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证80端口情况
firewall-cmd --query-port=80/tcp

显然80端口没有开启。
下面我们开启80端口:
firewall-cmd --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld
--permanent #永久生效,没有此参数重启后失效

个人学习使用,为了方便可关闭防火墙。
永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
刷新浏览器
配置完毕!
配置nginx开机自启动
vim /etc/rc.d/rc.local

本文介绍了如何在CentOS7系统上通过yum安装依赖,然后从官网下载Nginx源码,解压、配置、编译及安装。在安装过程中,详细展示了执行make和make install的步骤,并通过nginx -t测试配置文件的正确性。最后,文章讲解了如何启动Nginx,检查80端口状态,以及开启和验证80端口。此外,还涉及了通过firewall-cmd设置防火墙规则以允许80端口,并提供了关闭防火墙的命令。文章结尾提到了设置Nginx开机自启动的方法。

384

被折叠的 条评论
为什么被折叠?



