Linux中nginx手動安裝


本分類下有一個環境一鍵安裝.那這背后發生了什么呢?咱們手動使用源碼進行安裝.
1.首先保證有一個能聯網的centos.
2.百度 ningx 官網   點download  http://nginx.org/en/download.html  找到最新版的nginx下載地址. 發貼時最新的是1.12 http://nginx.org/download/nginx-1.12.0.tar.gz
3.進行centos  執行命令   

[Shell] 純文本查看 復制代碼
?
1
2
3
4
#安裝wget
yum install wget -y
#安裝gcc和c++編譯器
yum install gcc gcc-c++ -y


4.新建臨時目錄  /temp  然后下載並解壓. 命令如下

[Shell] 純文本查看 復制代碼
?
1
2
3
4
5
mkdir /temp ;
cd /temp ;
wget http: //nginx .org /download/nginx-1 .12.0. tar .gz
tar zxvf . /nginx-1 .12.0. tar .gz
cd /temp/nginx-1 .12.0


得到目錄

[root@localhost nginx-1.12.0]# pwd
/temp/nginx-1.12.0
[root@localhost nginx-1.12.0]# ll
total 724
drwxr-xr-x. 6 1001 1001   4096 Apr 17 11:42 auto
-rw-r--r--. 1 1001 1001 277049 Apr 12 22:46 CHANGES
-rw-r--r--. 1 1001 1001 421985 Apr 12 22:46 CHANGES.ru
drwxr-xr-x. 2 1001 1001   4096 Apr 17 11:42 conf
-rwxr-xr-x. 1 1001 1001   2481 Apr 12 22:46 configure
drwxr-xr-x. 4 1001 1001   4096 Apr 17 11:42 contrib
drwxr-xr-x. 2 1001 1001   4096 Apr 17 11:42 html
-rw-r--r--. 1 1001 1001   1397 Apr 12 22:46 LICENSE
drwxr-xr-x. 2 1001 1001   4096 Apr 17 11:42 man
-rw-r--r--. 1 1001 1001     49 Apr 12 22:46 README
drwxr-xr-x. 9 1001 1001   4096 Apr 17 11:42 src


5.linux三大安裝步驟   配置,編譯,安裝  第一步,配置
--prefix=/安裝后的路徑  注意這基本是所有安裝程序的通用的配置屬性
輸入命令

[Shell] 純文本查看 復制代碼
?
1
. /configure --prefix= /usr/local/nginx-mytest



接下來會報錯 如下

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


咱們需要安裝一個這樣的環境對能繼續 . 根據上面的意思.咱們先安裝 pcre 再指定路徑 指定方法在上面就是 --with-pcre=<path>
6.安裝pcre.百度這個詞得到官網. 然后找到下載路徑如下
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/  這里面有一些列表.咱們找到最新的即可 . 目前是
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz下載,解壓,編譯

[Shell] 純文本查看 復制代碼
?
1
2
3
4
mkdir /temp ;
cd /temp ;
wget ftp : //ftp .csx.cam.ac.uk /pub/software/programming/pcre/pcre-8 .39. tar .gz
tar zxvf pcre-8.39. tar .gz

到此得到了pcre的源碼路徑 為/temp/pcre-8.39
7.上一步得到安裝路徑/usr/local/pcre-8.39  接下來咱們從新編譯 nginx 注意別忘記  --with-pcre=<path>

[Shell] 純文本查看 復制代碼
?
1
2
cd /temp/nginx-1 .12.0
. /configure --prefix= /usr/local/nginx-mytest   --with-pcre= /temp/pcre-8 .39



發現完成

如果報錯Nginx編譯安裝錯誤error: the HTTP gzip module requires the zlib library

則需要安裝“zlib-devel”即可。SSH執行以下命令:

 代碼如下 復制代碼

yum install -y zlib-devel

然后再進行nginx的編譯。表示問題即可解決。


第二個命令就是 make   也就是編譯, 一般可以跟第三步一起執行,第三步是make install  .所以我們得到命令

[Shell] 純文本查看 復制代碼
?
1
make && make install



接下來去/usr/local/nginx-mytest看看吧.安裝成功了

 

啟動nginx:
/usr/local/nginx-mytest/sbin/nginx


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM