首先 安裝Development Tools工具包,這個(gè)工具包包括了GCC/GUN....等編譯器和庫,方便以后編譯nginx,命令如下
<pre>
yum groupinstall "Development Tools"
</pre>
其中 groupinstall 是安裝多個(gè)軟件包
安裝好后 開始安裝nginx 打開官網(wǎng)http://www.nginx.org/ 選擇Stable version 穩(wěn)定版 復(fù)制下載鏈接之后 執(zhí)行以下命令
<pre>
wget http://nginx.org/download/nginx-1.10.2.tar.gz
</pre>
我是先進(jìn)入/home/jiaruo/Downloads/目錄之后 在進(jìn)行wget下載的,把nginx包下載到/home/jiaruo/Downloads/這個(gè)目錄 wget是個(gè)下載工具 支持http https ftp 這三種協(xié)議下載
執(zhí)行l(wèi)s 命令 查看包是否下載完畢
<pre>
[root@localhost Downloads]# ls
nginx-1.10.2.tar.gz
[root@localhost Downloads]#
</pre>
nginx-1.10.2.tar.gz就是包的名稱,下面來解壓包 ,命令如下
<pre>tar xvf nginx-1.10.2.tar.gz</pre>
解壓命令自行百度,我也不太會,
執(zhí)行l(wèi)s命令查看解壓后的文件夾
<pre>
[root@localhost Downloads]# ls
nginx-1.10.2 nginx-1.10.2.tar.gz
[root@localhost Downloads]#
</pre>
進(jìn)入文件夾 并且查看文件
<pre>
[root@localhost Downloads]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.10.2]#
</pre>
我們看到其中有configure這個(gè)文件,configure腳本配置工具就是基礎(chǔ)之一,具體的自行百度,我們先來編譯,命令如下
<pre>./configure --prefix=/usr/local/nginx</pre>
然后會滾動一大堆不想看的英文字母,我掐指一算,絕對會有error出來.....果真給我面子
<pre>
./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.</pre>
大概的意思就是 缺少PCRE模塊 ,你可以禁止也可以安裝,咋安裝,不會 百度,的出來結(jié)果 去ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 這里下載,好吧 ,那我就下載,我們回到上級目錄 就是/home/jiaruo/Downloads/目錄 然后執(zhí)行命令
<pre>
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
</pre>
下載完畢之后ls 查看文件是否存在 如果不存在 請重?fù)Q資源下載 如果還不輕,請拿起你的磚頭砸電腦
我這里下載完畢 pcre-8.38.tar.gz 執(zhí)行解壓命令
<pre>tar xvf pcre-8.38.tar.gz </pre>
執(zhí)行l(wèi)s命令可以看出多了個(gè)pcre開頭的文件夾 我們進(jìn)入文件夾內(nèi)進(jìn)行編譯
<pre>
./configure --prefix=/usr/local/pcre
</pre>
編譯完畢 執(zhí)行 make && make install 命令,configure會在你的系統(tǒng)上測試存在的特性,make是編譯的意思, make install是安裝的意思,意思當(dāng)make沒出錯(cuò)的時(shí)候 就執(zhí)行安裝
<pre>make && make install</pre>
好了,安裝完畢之后我們返回上一級 進(jìn)入nginx的文件夾,然后繼續(xù)編譯,在上次測試的時(shí)候告訴我們了 缺少pcre模塊 如果安裝的話使用 --with-pcre=目錄 進(jìn)行安裝,這個(gè)目錄是指源碼目錄 不是安裝目錄,我在這個(gè)坑里待了2天,執(zhí)行以下命令
<pre>
./configure --prefix=/usr/local/nginx --with-pcre=/home/jiaruo/Downloads/pcre2-10.20
</pre>
./configure --prefix=你要安裝在哪里 --with-pcre=pcre解壓出來的目錄
完事之后 尼瑪又報(bào)錯(cuò)
<pre>
./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.
</pre>
缺少gzip模塊,我在裝一次 和pcre一樣
找gzip的下載目錄,找不到 然后百度得出結(jié)果http://www.zlib.net/zlib-1.2.8.tar.gz
繼續(xù)回到下載文件存檔的目錄,下載完畢執(zhí)行解壓,還需要我重復(fù)么,重復(fù)一次吧
<pre>
tar xvf zlib-1.2.8.tar.gz
</pre>
解壓后 會得到zlib-1.2.8 文件夾,進(jìn)入 然后編譯
<pre>./configure --prefix=/usr/local/zlib</pre>
編譯完成 繼續(xù)進(jìn)入nginx文件夾 然后測試 苦逼啊
<pre>
./configure --prefix=/usr/local/nginx \
--with-pcre=/home/jiaruo/Downloads/pcre2-10.20
--with-zlib=/home/jiaruo/Downloads/zlib-1.2.8
</pre>
老天保佑,在出錯(cuò)我就不裝了
...
...
...
<pre>
Configuration summary
- using PCRE library: /home/jiaruo/Downloads/pcre2-10.20
- OpenSSL library is not used
- using builtin md5 code
- sha1 library is not found
- using zlib library: /home/jiaruo/Downloads/zlib-1.2.8
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
</pre>
出現(xiàn)上面的內(nèi)容說明測試通過可以編譯和安裝
嘿 真特么好使 繼續(xù)編譯 && 安裝
<pre>make && make install</pre>
...
...
...
出先錯(cuò)誤<pre>cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/jiaruo/Downloads/pcre2-10.20 -I /home/jiaruo/Downloads/zlib-1.2.8 -I objs
-o objs/src/core/nginx.o
src/core/nginx.c
In file included from src/core/ngx_core.h:72,
from src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: error: pcre.h: No such file or directory
In file included from src/core/ngx_core.h:72,
from src/core/nginx.c:9:
src/core/ngx_regex.h:24: error: expected specifier-qualifier-list before ‘pcre’
make[1]: *** [objs/src/core/nginx.o] Error 1
make[1]: Leaving directory `/home/jiaruo/Downloads/nginx-1.10.2'
make: *** [build] Error 2</pre>
然后請教了下馮立松大神,發(fā)現(xiàn)是之前pcre版本問題 之前裝的是pcre2 已更正 然后 在重復(fù)pcre編譯之后 在進(jìn)到nginx 下面執(zhí)行
<pre>
./configure --prefix=/usr/local/nginx \
--with-pcre=/home/jiaruo/Downloads/pcre-8.38 \
--with-zlib=/home/jiaruo/Downloads/zlib-1.2.8
</pre>
沒錯(cuò)誤 然后繼續(xù) 編譯 安裝
<pre>make && make install</pre>
沒發(fā)現(xiàn)錯(cuò)誤,然后試試安裝成功 進(jìn)入目錄試試
<pre>
cd /usr/local/nginx/
</pre>
順利進(jìn)來 ls一下 發(fā)現(xiàn)有個(gè)conf 顧名思義 里面放的都是配置文件夾里面有個(gè)nginx.conf 就是主配置文件
我們進(jìn)入返回nginx根目錄 進(jìn)入sbin目錄 發(fā)現(xiàn)有個(gè)nginx 執(zhí)行
<pre>./nginx</pre>
沒抱任何錯(cuò)誤的話 說明啟動成功 我們查看進(jìn)程
<pre>
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps aux | grep nginx
root 56307 0.0 0.0 16208 632 ? Ss 00:21 0:00 nginx: master process ./nginx
nobody 56308 0.0 0.1 16628 1232 ? S 00:21 0:00 nginx: worker process
root 56314 0.0 0.0 103252 840 pts/0 S+ 00:22 0:00 grep nginx
[root@localhost sbin]#
</pre>
看到nginx的master(控制進(jìn)程) 和worker(服務(wù)進(jìn)程)都在運(yùn)行中,說明啟動成功,
在外網(wǎng)訪問ip,尼瑪 怎么報(bào)錯(cuò),怎么怎么,恩 防火墻,應(yīng)該是這貨搞得鬼
給我"沙特當(dāng)" 命令如下<pre>service iptables stop</pre>看到什么玩意ok 說明關(guān)閉成功 再次 訪問 恩 訪問成功
nginx安裝完畢 擼代碼去