首先,咱們要安裝個必要的軟件html
#yum install wgetnginx
由於Nginx以來與gcc的編譯環境,因此,在mini centos中須要安裝編譯環境來使Nginx可以編譯起來。c++
#yum install gcc-c++正則表達式
Nginx的http模塊須要使用pcre來解析正則表達式。centos
#yum -y install pcre pcre-devel瀏覽器
依賴的解壓包服務器
#yum -y install zlib zlib-devel測試
openssl安裝,Nginx提供http和https協議,https是大勢所趨ui
#yum install -y openssl openssl-develcode
好了,如今就輪到主角登場啦!!!
下載Nginx源碼
先去Nginx官網查看最新版的Nginx源碼地址:
https://nginx.org/en/download.html
https://nginx.org/download/nginx-1.10.3.tar.gz
#wget -c https://nginx.org/download/nginx-1.10.3.tar.gz
下面開始對其解壓
#tar -zxvf nginx-1.10.3.tar.gz
進入Nginx目錄
#cd nginx-1.10.3
這裏就是Nginx的全部源碼啦,下面就要對Nginx的源碼進行編譯啦!編譯命令三劍客登場!!!
#./configure
開始編譯
#make
#make install
OK,全部的工做都已經作完啦,下面開始啓動Nginx服務並在遠程測試
通常編譯安裝完的軟件都會放在/usr裏,這不是user,這是Unix System Resource,是Unix系統資源的縮寫。
咱們在/user/local/裏面發現了nginx,進入。
#cd /usr/local/nginx/
若是你找不到,試試這條命令吧
#whereis nginx
它會告訴你nginx在哪,nginx的命令在/usr/local/nginx/sbin目錄下
對於nginx的啓動,中止,我簡單的列舉下
./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload
./nginx -s quit
:此方式中止步驟是待nginx進程處理任務完畢進行中止。
./nginx -s stop
:此方式至關於先查出nginx進程id再使用kill命令強制殺掉進程。
查詢nginx進程:
ps aux|grep nginx
root 23045 0.0 0.0 24468 764 ? Ss 23:02 0:00 nginx: master process sbin/nginx
nobody 23046 0.0 0.1 24888 1232 ? S 23:02 0:00 nginx: worker process
看到這兩條進程狀態,你成功了。PS:grep是篩選,|是管道,Linux裏篩選的經常使用方式。
如今,在你的瀏覽器中輸入你遠端服務器的ip,看看是否有Nginx歡迎你的字樣。
若是沒有,關閉CentOS的防火牆試試。PS:防火牆關閉以後注意配置iptables
CentOS7.0以上默認firewall爲防火牆配置,咱們這裏改成iptables配置。
中止firewall
#systemctl stop firewalld.service
禁止firewall開機啓動
#systemctl disable firewalld.service