歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> ubuntu下nginx安裝手記

ubuntu下nginx安裝手記

日期:2017/2/27 16:02:44   编辑:Linux教程
Nginx是一個高性能的HTTP和反向代理服務器.
Nginx使用 Unix 下常用的 './configure && make && make install' 過程來編譯安裝.
configure 腳本確定系統所具有一些特性,特別是 nginx 用來處理連接的方法。然後,它創建 Makefile 文件。

官網:http://nginx.org/
下載頁面:http://nginx.org/download/nginx-1.2.6.tar.gz

1、模塊依賴性
gzip 模塊需要 zlib 庫
rewrite 模塊需要 pcre 庫
ssl 功能需要 openssl 庫
預先編譯好的安裝包
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

2、nginx的准備工作
下載nginx-1.2.6.tar.gz包到你指定的目錄下後,解壓:
tar zxvf nginx-1.2.6.tar.gz
解壓後在當前目錄下會生成一個nginx-1.2.6的目錄
進入解壓後的目錄,運行configure命令,
./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= option.
這是因為沒有PCRE library的原因所致,通過下面的命令安裝相關的lib即可解決

3、PCRE庫的安裝
官網:http://www.pcre.org/
下載頁面:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
選擇最新版本下載:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
1)解壓:
tar –zxvf pcre-8.10.tar.gz
解壓目錄為:pcre-8.10
然後進入到 cd pcre-8.10,進行配置、編譯、安裝
2)配置
./configure --prefix=/usr/local/pcre
3)編譯pcre
make
make pcre時會出錯
libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/home/mfcai/pcre-8.10'
make: *** [all] Error 2
安裝build-essential
apt-get install build-essential
4)安裝pcre
make install

4、nginx的安裝
1)配置
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/
注意:此處而不是安裝的路徑,應該是pcre源文件的路徑
正確的命令是:
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.10
2)編譯
make
3)安裝
make install

Nginx會被安裝在/usr/local/nginx目錄下(也可以使用參數--prefix=指定自己需要的位置),
安裝成功後 /usr/local/nginx 目錄下有四個子目錄分別是:conf、html、logs、sbin 。
其中 Nginx 的配置文件存放於 conf/nginx.conf,
bin文件是位於 sbin 目錄下的 nginx 文件。
確保系統的 80 端口沒被其他程序占用,運行 sbin/nginx 命令來啟動 Nginx,
打開浏覽器訪問此機器的 IP,如果浏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝並運行成功
Copyright © Linux教程網 All Rights Reserved