CentOS下安裝Nginx

來源:互聯網
上載者:User

標籤:虛擬機器   error   下載檔案   

1.系統準備 

 在虛擬機器安裝CentOS6.7系統,給系統設定IP和dns讓系統可以連網,接下來就可以進行環境準備。

2.環境準備

 安裝相關編譯環境和依賴關係

 yum -y install gcc gcc-c++ autoconf automake make

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/7F/CE/wKiom1ctltvjNeO3AAB4WElDKX4229.png" title="QQ圖片20160507152756.png" alt="wKiom1ctltvjNeO3AAB4WElDKX4229.png" />

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/7F/CC/wKioL1ctmVvwE5OsAACkCoja1xc994.png" style="float:none;" title="2.png" alt="wKioL1ctmVvwE5OsAACkCoja1xc994.png" />


可以到此頁面下載自己想要的版本,目前最新的版本nginx-1.10.0,本文中使用的是nginx-1.7.4

http://nginx.org/en/download.html

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/7F/CE/wKiom1ctmILDPMULAABXvCCeTDc879.png" title="3.png" style="float:none;" alt="wKiom1ctmILDPMULAABXvCCeTDc879.png" />

使用以下命令下載檔案:wget http://nginx.org/download/nginx-1.7.4.tar.gz

將下載下來的Nginx上傳到/opt/nginx目錄下。運行“tar -zxvf nginx-1.7.4.tar.gz”進行解壓。

配置:./configure

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/7F/CC/wKioL1ctn2OTp8MrAACLHb081XM758.png" title="1" style="float:none;" alt="wKioL1ctn2OTp8MrAACLHb081XM758.png" />

如果沒有裝PCRE相關的,會產生如下報錯

650) this.width=650;" src="http://www.linuxidc.com/upload/2015_03/15031418518380.jpg" alt="15031418518380.jpg" />

同樣的,沒有裝zlib也會產生相關報錯

./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.


如果提示同樣的錯誤;

執行命令尋找PCRE的安裝位置:file -name pcre

得到的是:./auto/lib/pcre

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/7F/CC/wKioL1ctn2OT9dOXAAAcxWltgGA096.png" title="2" style="float:none;" alt="wKioL1ctn2OT9dOXAAAcxWltgGA096.png" />


根據提示在後面添加參數指定Path

執行命令:./configure --with-pcre=./auto/lib/pcre


如果看到以上的圖片,表示配置成功了,執行以下命令安裝:

make && make install

提示以下錯誤:

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/7F/CE/wKiom1ctnoqg2FNtAABJACpXV_s534.png" title="3" style="float:none;" alt="wKiom1ctnoqg2FNtAABJACpXV_s534.png" />

重新執行:./configure

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/7F/CC/wKioL1ctn2STa1-EAABz_YRpTQE875.png" title="4" style="float:none;" alt="wKioL1ctn2STa1-EAABz_YRpTQE875.png" />

再執行:make && make install

安裝完成!

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/7F/CE/wKiom1ctnouQ8MjUAACeGTFFtN8028.png" title="5" style="float:none;" alt="wKiom1ctnouQ8MjUAACeGTFFtN8028.png" />


修改設定檔:

切換目錄:cd /usr/local/nginx/conf

修改檔案:vi nginx.conf

650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/7F/CE/wKiom1ctoJfweIkaAAAUGeUR9EA243.png" title="11.png" style="float:none;" alt="wKiom1ctoJfweIkaAAAUGeUR9EA243.png" />


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/7F/CE/wKiom1ctoS-jJdJmAABy-l5PU6o611.png" style="float:none;" title="14.png" alt="wKiom1ctoS-jJdJmAABy-l5PU6o611.png" />


切換到sbin目錄:cd /usr/local/nginx/sbin


啟動Nginx:./nginx

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/7F/CE/wKiom1ctoS-BB4VZAAAc8f0FLZo058.png" title="13.png" style="float:none;" alt="wKiom1ctoS-BB4VZAAAc8f0FLZo058.png" />

開啟瀏覽器,輸入以下地址訪問吧:


http://你的伺服器IP

看到以下資訊了嗎?


650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/7F/CC/wKioL1ctoXGiGlUDAABAGUsDGKo177.png" style="float:none;" title="12.png" alt="wKioL1ctoXGiGlUDAABAGUsDGKo177.png" />


配置Nginx開機啟動,vi /etc/rc.d/rc.local

在檔案末尾添加“/usr/local/nginx/sbin/nginx”


Nginx常用命令:

重新載入設定檔:/usr/local/nginx/sbin/nginx -s reload

停止Nginx服務:/usr/local/nginx/sbin/nginx -s stop



本文出自 “妖風” 部落格,請務必保留此出處http://6649329.blog.51cto.com/6639329/1771022

CentOS下安裝Nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.