安裝必要依賴插件
yum?install?-y?gcc?gcc-c++?pcre? pcre-devel?zlib?zlib-devel?openssl?openssl-devel?wget
創(chuàng)建文件夾并切換過去
mkdir?/customer?&&?cd?/customer
下載安裝包 (同樣如果想安裝其他的版本,可以去下面官網(wǎng)鏈接,選擇其他版本的鏈接進(jìn)行拷貝替換)
wget?https://nginx.org/download/nginx-1.16.0.tar.gz
解壓并安裝
tar?zxvf?nginx-1.16.0.tar.gz cd?nginx-1.16.0 ./configure?--prefix=/usr/local/nginx make?&&?make?install
添加全局命令
ln?-s?/usr/local/nginx/sbin/nginx?/usr/bin/nginx
測試安裝
nginx -v
如下圖,則安裝成功:
驗(yàn)證服務(wù)是否啟動成功
netstat?-ntlp?|?grep?nginx
如下:
添加nginx服務(wù)
vim?/lib/systemd/system/nginx.service
將以下內(nèi)容插入:
[unit] description=nginx 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
以服務(wù)的方式啟動nginx
pkill?nginx systemctl?start?nginx
查看服務(wù)是否啟動
?systemctl?status?nginx ?netstat?-ntlp?|?grep?nginx
配置nginx服務(wù)開機(jī)自動啟動
systemctl?enable?nginx
這下子就安裝完畢了 ,配置文件在:
vim?/usr/local/nginx/conf/nginx.conf
可選:
nginx的版本號默認(rèn)是打開的,可以在默認(rèn)的錯(cuò)誤頁面和http響應(yīng)頭中查看到。
不同版本,特別是低版本的nginx可能存在漏洞,所以如果不希望被別人獲取到版本號的話,可以選擇進(jìn)行版本號隱藏。
隱藏nginx版本號
cd?/usr/local/nginx/conf vim?nginx.conf
nginx.conf文件的“server_tokens”修改成”off“:
http?{ ... server_tokens?off; ... }
再修改fastcgi.conf
vim fastcgi.conf
修改如下行
fastcgi_param?server_software?nginx/$nginx_version; #?改為: fastcgi_param?server_software?nginx;
重啟nginx
systemctl?restart?nginx
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END