
NGINX的下載界面會(huì)看到有三個(gè)版本

- 開發(fā)版:Mainline version
- 穩(wěn)定版:Stable version
- 歷史版:Legacy versions
注意:企業(yè)安裝NGINX需要使用穩(wěn)定版本
1. 環(huán)境準(zhǔn)備
# 查看系統(tǒng)版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
# 確定系統(tǒng)網(wǎng)絡(luò)環(huán)境,是否可訪問公網(wǎng)
[root@localhost ~]# ping -c 4 www.baidu.com
# 關(guān)閉防火墻
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# systemctl status firewalld.service
# 修改主機(jī)名稱
[root@localhost ~]# hostnamectl set-hostname web-01
# 關(guān)閉selinux
[root@localhost ~]# sed -i.backup 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
# 重啟系統(tǒng)
[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. 啟動(dòng)NGINX服務(wù)
# 檢查配置文件是否正確
[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
# 啟動(dòng)NGINX服務(wù)
[root@web-01 ~]# systemctl start nginx.service
[root@web-01 ~]# systemctl enable nginx.service
# 檢查NGINX服務(wù)運(yùn)行狀態(tài)
[root@web-01 ~]# systemctl status nginx.service
[root@web-01 ~]# ps aux|grep nginx
[root@web-01 ~]# ss -nlutp|grep 80
2.4. 訪問網(wǎng)頁測(cè)試

命令行訪問
[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 >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
3. NGINX安裝目錄
為了讓大家更加清晰的了解nginx軟件的全貌,我們有必要介紹一下NGINX安裝后整體的目錄結(jié)構(gòu)和文件功能。RPM包方式安裝使用如下命令查看
[root@web-01 ~]# rpm -ql nginx
NGINX安裝目錄詳細(xì)概述
| 路徑 | 類型 | 作用 |
|---|---|---|
| /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編碼轉(zhuǎn)換映射文件 |
| /etc/nginx/mime.types | 配置文件 | HTTP協(xié)議的Content-Type |
| /etc/sysconfig/nginx /etc/sysconfig/nginx-debug /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service |
配置文件 | 配置系統(tǒng)守護(hù)進(jìn)程管理器 |
| /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幫助手冊(cè) |
| /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默認(rèn)站點(diǎn)目錄 |