nginx怎么安裝

nginx怎么安裝

nginx可以使用各平臺(tái)的默認(rèn)包來安裝,本文是介紹使用源碼編譯安裝,包括具體的編譯參數(shù)信息。

正式開始前,編譯環(huán)境gcc g++ 開發(fā)庫之類的需要提前裝好,這里默認(rèn)你已經(jīng)裝好。

ububtu平臺(tái)編譯環(huán)境可以使用以下指令

1

2

aptget install buildessential

aptget install libtool

centos平臺(tái)編譯環(huán)境使用如下指令

安裝make:

1

yum y install gcc automake autoconf libtool make

安裝g++:

1

yum install gcc gccc++

下面正式開始
—————————————————————————
一般我們都需要先裝pcre, zlib,前者為了重寫rewrite,后者為了gzip壓縮。
1.選定源碼目錄
可以是任何目錄,本文選定的是/usr/local/src

1

cd /usr/local/src

2.安裝PCRE庫
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/?下載最新的 PCRE 源碼包,使用下面命令下載編譯和安裝 PCRE 包:

1

2

3

4

5

6

7

cd /usr/local/src

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz

tar zxvf pcre8.37.tar.gz

cd pcre8.34

./configure

make

make install

3.安裝zlib庫
http://zlib.net/zlib-1.2.8.tar.gz?下載最新的 zlib 源碼包,使用下面命令下載編譯和安裝 zlib包:

1

2

3

4

5

6

7

8

cd /usr/local/src

?

wget http://zlib.net/zlib-1.2.8.tar.gz

tar zxvf zlib1.2.8.tar.gz

cd zlib1.2.8

./configure

make

make install

4.安裝ssl(某些vps默認(rèn)沒裝ssl)

1

2

3

cd /usr/local/src

wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz

tar zxvf openssl1.0.1t.tar.gz

5.安裝nginx

Nginx 一般有兩個(gè)版本,分別是穩(wěn)定版和開發(fā)版,您可以根據(jù)您的目的來選擇這兩個(gè)版本的其中一個(gè),下面是把 Nginx 安裝到 /usr/local/nginx 目錄下的詳細(xì)步驟:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

cd /usr/local/src

wget http://nginx.org/download/nginx-1.4.2.tar.gz

tar zxvf nginx1.4.2.tar.gz

cd nginx1.4.2

?

./configure sbinpath=/usr/local/nginx/nginx

confpath=/usr/local/nginx/nginx.conf

pidpath=/usr/local/nginx/nginx.pid

withhttp_ssl_module

withpcre=/opt/app/openet/oetal1/chenhe/pcre8.37

withzlib=/opt/app/openet/oetal1/chenhe/zlib1.2.8

withopenssl=/opt/app/openet/oetal1/chenhe/openssl1.0.1t

?

make

make install

–with-pcre=/usr/src/pcre-8.34 指的是pcre-8.34 的源碼路徑。
–with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源碼路徑。

安裝成功后 /usr/local/nginx 目錄下如下

1

2

3

4

5

6

fastcgi.conf????????????koiwin???????????? nginx.conf.default

fastcgi.conf.default????logs????????????????scgi_params

fastcgi_params??????????mime.types??????????scgi_params.default

fastcgi_params.default??mime.types.default??uwsgi_params

html????????????????????nginx?????????????? uwsgi_params.default

koiutf???????????????? nginx.conf??????????winutf

6.啟動(dòng)
確保系統(tǒng)的 80 端口沒被其他程序占用,運(yùn)行/usr/local/nginx/nginx 命令來啟動(dòng) Nginx,

1

netstat ano|grep 80

如果查不到結(jié)果后執(zhí)行,有結(jié)果則忽略此步驟(ubuntu下必須用sudo啟動(dòng),不然只能在前臺(tái)運(yùn)行)

1

sudo?/usr/local/nginx/nginx

打開瀏覽器訪問此機(jī)器的 IP,如果瀏覽器出現(xiàn) Welcome to nginx! 則表示 Nginx 已經(jīng)安裝并運(yùn)行成功。

nginx怎么安裝

—————————————————–
到這里nginx就安裝完成了,如果只是處理靜態(tài)html就不用繼續(xù)安裝了

如果你需要處理php腳本的話,還需要nginx怎么安裝

下面安裝排錯(cuò)

附:可能遇到的錯(cuò)誤和一些幫助信息

1.1編譯pcre錯(cuò)誤

1

2

3

4

5

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 `/usr/local/src/pcre8.34

make: *** [all] Error 2

1

2

3

4

5

aptget install g++

aptget install buildessential

make clean

./configure

make

1

2

3

4

5

make:?***?No?rule?to?make?target?`build‘,?needed?by?`default’.??Stop.

./configure:?error:?SSL?modules?require?the?OpenSSL?library.

You?can?either?do?not?enable?the?modules,?or?install?the?OpenSSL?library

into?the?system,?or?build?the?OpenSSL?library?statically?from?the?source

with?nginx?by?using?withopenssl=path>?option.

1

2

aptget?install?openssl

aptget?install?libssldev

1

yum y install openssl openssldevel

1

2

3

4

5

6

7

./configure

????sbinpath=/usr/local/nginx/nginx

????confpath=/usr/local/nginx/nginx.conf

????pidpath=/usr/local/nginx/nginx.pid

????withhttp_ssl_module

????withpcre=../pcre4.4

????withzlib=../zlib1.1.3

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊5 分享