Nginx從入門到實戰(二):Linux安裝Nginx

前序:Nginx從入門到實戰(一):介紹

Linux安裝Nginx

注意: docker安裝更便捷,這裏介紹原生安裝。

1.安裝依賴包

​ 所需依賴有:pcre zlib zlib-devel gcc-c++ libtool openssl openssl-devel

​ 如果安裝比較慢的話,可以切換鏡像源,切換方式見如下文章https://blog.csdn.net/wdy_2099/article/details/70578529

安裝命令如下:

yum -y install make pcre zlib zlib-devel gcc-c++ libtool openssl openssl-devel 

2.安裝Nginx

​ 下載nginx-1.12.2.tar.gz包(下載地址 http://nginx.org/download/)可以根據實際情況下載其他版本。

2.1 首先解壓:

[root@localhost nginx]# tar -xvf nginx-1.12.2.tar.gz 

2.2 解壓後,進入目錄nginx-1.12.2,然後執行./configure 執行檢查操作
開啓stream塊

 ./configure --with-stream 
[root@localhost nginx]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure 

2.3 最後執行編譯

[root@localhost nginx-1.12.2]# make && make install

2.4 編譯以後會在/usr/local下生成nginx文件夾,sbin下有啓動腳本

/usr/local/nginx/sbin

[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ls
nginx

3.啓動Nginx

啓動sbin下的nginx

[root@localhost sbin]# ./nginx
[root@localhost sbin]# 

訪問默認80端口:(我這邊服務器地址爲http://192.168.1.117:80/),出現以下界面則爲啓動成功:

在這裏插入圖片描述

注意:CentoS7中操作防火牆的規則外部訪問需要開放對應端口

查看開放的端口號 
firewall-cmd --list-all 
設置開放的端口號 
firewall-cmd --add-service=http –permanent 
firewall-cmd --add-port=80/tcp --permanent 
重啓防火牆 
firewall-cmd –reload 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章