1. 程式人生 > 其它 >201924072021-2022-2 《網路與系統攻防技術》實驗四實驗報告

201924072021-2022-2 《網路與系統攻防技術》實驗四實驗報告

版本區別

常用版本分為四大陣營

Nginx開源版  http://nginx.org/ Nginx plus

商業版  https://www.nginx.com

openresty  http://openresty.org/cn/

Tengine     http://tengine.taobao.org

 

安裝步驟

這裡是開源版  nginx-1.21.6.tar.gz

1、將tar包上傳到linux伺服器,解壓縮

2、編譯安裝

./configure 
./configure --prefix=/usr/local/nginx

--指定安裝到/usr/local/nginx目錄下

 

如果出現警告或報錯

提示1:

checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found

需要安裝gcc

yum install -y gcc

 

 

 

 

 

 提示2

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

  

 

 

 需安裝perl庫

yum install -y pcre pcre-devel

提示3

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using
--with-zlib=<path> option.

 

 

 需安裝zlib庫

yum install -y zlib zlib-devel

接下來執行 

  make               ##編譯

 

 

 

 

  make install    ##安裝

安裝完後可以看到local目錄下已經多了一個nginx目錄

 

3、 啟動Nginx

進入安裝好的目錄 /usr/local/nginx/sbin

相關啟停命令
./nginx 啟動 ./nginx -s stop 快速停止 ./nginx -s quit 優雅關閉,在退出前完成已經接受的連線請求 ./nginx -s reload 重新載入配置

執行 ./nginx就已經啟動了

此時在瀏覽器輸入 ip 

 

 顯示無法訪問此網站

 

 

 關閉防火牆

systemctl stop firewalld.service

關於防火牆

禁止防火牆開機啟動
systemctl disable firewalld.service
放行埠
firewall-cmd --zone=public --add-port=80/tcp --permanent
重啟防火牆
firewall-cmd --reload

 

重新整理網頁,出現Welcome to nginx! 表示啟動成功

 

建立啟動nginx的便捷指令碼

vi /usr/lib/systemd/system/nginx.service

 指令碼內容    路徑要對應安裝路徑

[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

 

 使用此指令碼啟動nginx

檢視當前nginx程序
ps -ef | grep nginx

關閉nginx
./nginx -s stop

使用上述指令碼啟動nginx
systemctl start nginx

檢視nginx狀態  圖中綠色部分 Active: active (running) 則表示啟動成功
systemctl status nginx

 

 開機啟動

systemctl enable nginx.service

 reboot重啟後 ps -ef | grep nginx   列表有nginx表示開機自啟動成功