nginx官網不同版本下載地址:http://nginx.org/download/
我使用的是nginx-1.9.8.tar.gz
- 安裝其他支持軟件
- 可以使用rpm –q xxx 查詢庫是否已經安裝成功
- gcc、make工具
- rewrite 模塊需要 pcre 庫 ( 下載: http://www.pcre.org/ )
- gzip 模塊需要 zlib 庫 ( 下載: http://www.zlib.net/ )
- ssl 功能需要 openssl 庫 ( 下載: http://www.openssl.org/ )
-
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
- 支持Rewrite(但是我沒有裝這個)
PCRE 作用是讓 Ngnix 支持 Rewrite 功能。
使用yum源安裝: yum -y install pcre*
或使用wget方式安裝
1,下載 PCRE 安裝包 [root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz 2、解壓安裝包: [root@bogon src]# tar zxvf pcre-8.35.tar.gz 3、進入安裝包目錄 [root@bogon src]# cd pcre-8.35 4、編譯安裝 [root@bogon pcre-8.35]# ./configure [root@bogon pcre-8.35]# make && make install 5、查看pcre版本 [root@bogon pcre-8.35]# pcre-config --version - 源碼安裝nginx1.9.9
- 切換到root目錄下
- 下載:wget http://nginx.org/download/nginx-1.9.8.tar.gz
- 解壓縮 tar -zxvf nginx-1.9.8.tar.gz
- 編譯安裝
- cd nginx-1.9.9
- ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
這里也可以添加其他模塊,例如:rewrit模塊(--with-pcre) --prefix指定安裝的目錄
--with-http_stub_status_module啟用狀態統計 - 如果是使用wget方式則configure時,需要指定pcre
./configure --prefix=/usr/local/nginx \ --with-http_ssl_module --with-http_spdy_module \ --with-http_stub_status_module --with-pcre
- make && make install
- 檢測配置或安裝是否成功:/usr/local/nginx/sbin/nginx -t
如果出現下列信息,則標識安裝或配置成功
the configuration file /usr/local/nginx/conf/nginx.conf syntax is o
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
- 啟動,停止nginx服務
#/usr/local/nginx/sbin/nginx #/usr/local/nginx/sbin/nginx -s stop
- nginx啟動好后啟動tomcat,此時輸入http://主機ip地址即可看到“My web!”
- 在/etc/profile 添加nginx的path全局環境變量,則可以直接使用nginx命令