NGINX的下载界面会看到有三个版本
- 开发版:Mainline version
- 稳定版:Stable version
- 历史版:Legacy versions
注意:企业安装NGINX需要使用稳定版本
1. 环境准备
# 查看系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
# 确定系统网络环境,是否可访问公网
[root@localhost ~]# ping -c 4 www.baidu.com
# 关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# systemctl status firewalld.service
# 修改主机名称
[root@localhost ~]# hostnamectl set-hostname web-01
# 关闭selinux
[root@localhost ~]# sed -i.backup 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
# 重启系统
[root@localhost ~]# reboot
2. 开始安装NGINX
2.1. 配置NGINX YUM源
[root@web-01 ~]# cat > /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
EOF
2.2. 安装NGINX软件
[root@web-01 ~]# yum install -y nginx
# 查看nginx版本
[root@web-01 ~]# nginx -v
nginx version: nginx/1.18.0
2.3. 启动NGINX服务
# 检查配置文件是否正确
[root@web-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# 启动NGINX服务
[root@web-01 ~]# systemctl start nginx.service
[root@web-01 ~]# systemctl enable nginx.service
# 检查NGINX服务运行状态
[root@web-01 ~]# systemctl status nginx.service
[root@web-01 ~]# ps aux|grep nginx
[root@web-01 ~]# ss -nlutp|grep 80
2.4. 访问网页测试
命令行访问
[root@web-01 ~]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
3. NGINX安装目录
为了让大家更加清晰的了解nginx软件的全貌,我们有必要介绍一下NGINX安装后整体的目录结构和文件功能。RPM包方式安装使用如下命令查看
[root@web-01 ~]# rpm -ql nginx
NGINX安装目录详细概述
路径 | 类型 | 作用 |
---|---|---|
/etc/nginx /etc/nginx/nginx.conf /etc/nginx/conf.d /etc/nginx/conf.d/default.conf |
配置文件 | NGINX主配置文件 |
/etc/nginx/fastcgi_params /etc/nginx/scgi_params /etc/nginx/uwsgi_params |
配置文件 | CGI、FastCGI、UwCGI配置文件 |
/etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf |
配置文件 | NGINX编码转换映射文件 |
/etc/nginx/mime.types | 配置文件 | HTTP协议的Content-Type |
/etc/sysconfig/nginx /etc/sysconfig/nginx-debug /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service |
配置文件 | 配置系统守护进程管理器 |
/etc/logrotate.d/nginx | 配置文件 | NGINX日志轮询,日志切割配置文件 |
/usr/sbin/nginx /usr/sbin/nginx-debug |
命令 | NGINX管理命令 |
/usr/share/doc/nginx-1.18.0 /usr/share/doc/nginx-1.18.0/COPYRIGHT /usr/share/man/man8/nginx.8.gz |
目录 | NGINX帮助手册 |
/var/cache/nginx | 目录 | NGINX资源缓存目录 |
/var/log/nginx | 目录 | NGINX日志目录 |
/etc/nginx/modules /usr/lib64/nginx /usr/lib64/nginx/modules |
目录 | NGINX模块目录 |
/usr/share/nginx /usr/share/nginx/html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html |
目录 | NGINX默认站点目录 |
网友评论