當(dāng)前操作系統(tǒng):Redhat 7.8
1.安裝依賴包
- 在線安裝:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel - 離線安裝:
yum localinstall *.rpm
redhat7.8離線包下載地址:https://mirrors.aliyun.com/centos-vault/7.8.2003/
rpm包下載清單:

截圖.png
2.下載并解壓安裝包
下載nginx安裝包
wget http://nginx.org/download/nginx-1.21.6.tar
tar -xvf nginx-1.21.6.tar
3.安裝nginx
cd nginx-1.21.6
#創(chuàng)建nginx目錄
mkdir /usr/local/nginx
#執(zhí)行命令 考慮到后續(xù)安裝ssl證書(shū) 添加兩個(gè)模塊
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#執(zhí)行make命令
make
#執(zhí)行make install命令
make install
4.配置nginx.conf
#在nginx.conf中添加虛擬站點(diǎn)配置引用
include vhost/*.conf;
5.配置虛擬站點(diǎn)(***.com.conf)
upstream a_api_server{
server 10.86.237.108:8091;
server 10.86.237.109:8091;
}
server {
listen 443 ssl;
server_name ***.com;
ssl_certificate /usr/local/nginx/conf/cert/***.com.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/***.com.key;
ssl_session_timeout 5m;
ssl_ciphers ***;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
add_header X-Frame-Options DENY;
location /admin/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://a_api_server/admin/;
}
}
6.配置開(kāi)機(jī)啟動(dòng)
cd /etc/systemd/system vi nginx.service
nginx.service內(nèi)容:
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
設(shè)置開(kāi)機(jī)自啟動(dòng):
systemctl enable nginx
常用命令:
#啟動(dòng)nginx服務(wù)
systemctl start nginx
#重新加載配置
systemctl reload nginx
#重新啟動(dòng)服務(wù)
systemctl restart nginx
#停止開(kāi)機(jī)自啟動(dòng)
systemctl disable nginx
#關(guān)閉防火墻命令:
systemctl stop firewalld
#禁用防火墻命令:
systemctl disable firewalld