centos上nginx的安裝

木叔發表於2016-11-08
安裝步驟:
 
1、下載nginx,執行:wget http://nginx.org/download/nginx-1.10.2.tar.gz
2、解壓,執行:tar vxzf nginx-1.10.2.tar.gz
3、安裝,切換到nginx解壓目錄下,執行:./configure --prefix=/usr/local/nginx
  遇到問題:
  執行時報錯:
  checking for C compiler ... not found
  ./configure: error: C compiler cc is not found
  原因:缺少編譯環境
  解決:
  安裝gcc,執行:yum install gcc
 
4、繼續執行:./configure --prefix=/usr/local/nginx
  遇到問題:
  ./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.
  原因:缺少rewrite模組,需要安裝PCRE library(即正規表示式)
  解決:
  安裝pcre library,執行:yum install pcre
  安裝完成後再安裝pcre-devel(開發使用包):yum install pcre-devel
 
5、安裝完成後再次執行./configure --prefix=/usr/local/nginx
6、安裝,執行:make && make install
7、切換到/usr/local下發現有nginx目錄,安裝完成
8、繼續切換到/usr/local/nginx下檢視有目錄為:

 ....conf 配置檔案  

 ... html 網頁檔案

 ...logs  日誌檔案 

 ...sbin  主要二進位制程式

9、啟動nginx,執行:./sbin/nginx 
  遇到問題:
  啟動過程中可能出現:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  原因:80埠被佔用
  解決:
  執行:netstat -antp(或netstat -tunlp) 檢視佔用埠的程式,如:
  
  殺掉程式即可,執行:kill -9 2985 //2985是程式號
 
10、再次啟動,執行:./sbin/nginx  啟動成功沒有任何提示
 
訪問:
安裝成功後可通過虛擬機器ip直接訪問主機,正常情況會出現nginx歡迎頁面,但是發現無法訪問,windows下ping主機ip可以ping通,但是執行:telnet ip 埠    無法訪問,說明可能是linux防火牆的問題
  注:telnet開啟方法:控制皮膚--->程式和功能--->開啟或關閉windows功能--->勾選Telnet伺服器及Telnet客戶端兩個選項,點選確定--->在windows視窗下執行telnet嘗試即可
然後依次執行以下操作允許80埠的訪問:
1、 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  
2、/etc/init.d/iptables save  
3、 /etc/init.d/iptables restart  
 
操作具體反映如下:  
 
 至此,再次訪問主機ip地址即可出現nginx歡迎頁了,主機已可訪問虛擬機器的nginx服務。
 
 
 
 

相關文章