1. 程式人生 > >Nginx之解壓編譯安裝-yellowcong

Nginx之解壓編譯安裝-yellowcong

安裝前準備

對於nginx編譯安裝需要先安裝編譯 的工具,然後再安裝nginx依賴

yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
1
2
下載nginx

#管網映象
http://nginx.org/download/

#獲取nginx,官方地址
wget http://nginx.org/download/nginx-1.10.1.tar.gz
wget http://nginx.org/download/nginx-1.6.2.tar.gz

#這個是我自己七牛的伺服器
wget http://yellowcong.qiniudn.com/nginx-1.10.1.tar.gz

#解壓 /usr/local/nginx 目錄
tar -zxvf nginx-1.10.1.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
安裝nginx

第一步是配置,第二步是編譯安裝

配置nginx

#進入到nginx-1.10.1 ,並配置nginx
cd nginx-1.10.1

#配置nginx
#--prefix 指定安裝的目錄
#/usr/local/nginx 是安裝目錄,不能和自己下載的檔案目錄重了
#./configure --prefix=/usr/local/nginx

#帶ssl stub_status模組 新增strem模組 –with-stream,這樣就能傳輸tcp協議了
#http_stub_status_module 狀態監控
#http_ssl_module 配置https
#stream 配置tcp得轉發
#http_gzip_static_module 壓縮
#http_sub_module 替換請求
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream

#帶使用者得方式
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
到nginx的目錄下,然後配置nginx


看到了結果,就差不多 代表成功了

 

編譯安裝

只要出現上面的,差不多就是完事了,可以編譯了,如果還是有錯誤,可以使用yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel命令,安裝所有依賴

#編譯安裝
make && make install
1
2


安裝成功

安裝成功後,會在./configure --prefix=/usr/local/nginx,指定的目錄/usr/local/nginx建立4個 資料夾。具體功能下面有介紹。


#啟動 nginx服務
/usr/local/nginx/sbin/nginx
#停止服務
/usr/local/nginx/sbin/nginx -s stop

#重啟服務
/usr/local/nginx/sbin/nginx -s reload

#檢視啟動情況
ps -ef|grep nginx

#檢視是否啟動成功
curl 192.168.100.10

#檢視埠情況
netstat -ano|grep 80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
nginx正常執行


網頁訪問正常


檢視埠情況


目錄結構

目錄 作用
conf 用於儲存nginx配置檔案
html 用於存放靜態網頁
logs 存放日誌
sbin 用於存放 nginx這種工具


錯誤合集

1、./configure: error: C compiler cc is not found

錯誤訊息

[[email protected] nginx-1.10.1]# ./configure
checking for OS
+ Linux 3.10.0-514.26.2.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found
1
2
3
4
5
6
7
解決辦法
安裝編譯工具

[[email protected] nginx-1.10.1]# yum -y install gcc gcc-c++ autoconf automake make
1
2
然後再次編譯,可以了,然而又遇到了新問題


2、checking for PCRE library … not found

pcre沒有發現的問題,需要安裝pcre ,他作用是讓ngnix支援rewrite功能
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./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.
1
2
3
4
5
6
7
8
9
10
3、安裝pcre

我打算安裝的,結果發現這雞毛已經安裝過了,然後我需要在./configure的時候指定目錄./configure --with-pcre=./auto/lib/pcre

[[email protected] nginx-1.10.1]# yum install pcre
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package pcre-8.32-15.el7_2.1.x86_64 already installed and latest version
1
2
3
4
5
6
7
8
簡單說一下centos如何查詢檔案

#查詢檔案,需要獲取pcre的安裝位置
find -name pcre
1
2
4、安裝zlib

還缺少zlib library資訊,感覺編譯nginx是一個錯誤,直接使用rpm安裝包多爽,安裝zlib吧,別說別的了

yum -y install make zlib zlib-devel gcc-c++ libtool
1
錯誤資訊

./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.
1
2
3
4


5、cp: “conf/koi-win” 與”/usr/local/nginx/nginx-1.6.2/conf/koi-win” 為同一檔案

檔案為同一個檔案的問題

cp: "conf/koi-win" 與"/usr/local/nginx/nginx-1.6.2/conf/koi-win" 為同一檔案
make[1]: *** [install] 錯誤 1
make[1]: 離開目錄“/usr/local/nginx/nginx-1.6.2”
make: *** [install] 錯誤 2
1
2
3
4
5

---------------------
作者:狂飆的yellowcong
來源:CSDN
原文:https://blog.csdn.net/yelllowcong/article/details/76382900
版權宣告:本文為博主原創文章,轉載請附上博文連結!