實(shí)戰(zhàn)Linux CentOS7 安裝LNMP環(huán)境架構(gòu)過程之編譯nginx

首先 安裝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)閉成功 再次 訪問 恩 訪問成功


QQ20161021-0.png

nginx安裝完畢 擼代碼去

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子钞瀑,更是在濱河造成了極大的恐慌采够,老刑警劉巖地啰,帶你破解...
    沈念sama閱讀 219,490評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)定铜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來怕敬,“玉大人揣炕,你說我怎么就攤上這事《颍” “怎么了畸陡?”我有些...
    開封第一講書人閱讀 165,830評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長虽填。 經(jīng)常有香客問我罩锐,道長,這世上最難降的妖魔是什么卤唉? 我笑而不...
    開封第一講書人閱讀 58,957評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮仁期,結(jié)果婚禮上桑驱,老公的妹妹穿的比我還像新娘。我一直安慰自己跛蛋,他們只是感情好熬的,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著赊级,像睡著了一般押框。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上理逊,一...
    開封第一講書人閱讀 51,754評論 1 307
  • 那天橡伞,我揣著相機(jī)與錄音盒揉,去河邊找鬼。 笑死兑徘,一個(gè)胖子當(dāng)著我的面吹牛刚盈,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播挂脑,決...
    沈念sama閱讀 40,464評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼藕漱,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了崭闲?” 一聲冷哼從身側(cè)響起肋联,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎刁俭,沒想到半個(gè)月后橄仍,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,847評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡薄翅,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評論 3 338
  • 正文 我和宋清朗相戀三年沙兰,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片翘魄。...
    茶點(diǎn)故事閱讀 40,137評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡鼎天,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出暑竟,到底是詐尸還是另有隱情斋射,我是刑警寧澤,帶...
    沈念sama閱讀 35,819評論 5 346
  • 正文 年R本政府宣布但荤,位于F島的核電站罗岖,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏腹躁。R本人自食惡果不足惜桑包,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望纺非。 院中可真熱鬧哑了,春花似錦、人聲如沸烧颖。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽炕淮。三九已至拆火,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背们镜。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評論 1 272
  • 我被黑心中介騙來泰國打工币叹, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人憎账。 一個(gè)月前我還...
    沈念sama閱讀 48,409評論 3 373
  • 正文 我出身青樓套硼,卻偏偏與公主長得像,于是被迫代替她去往敵國和親胞皱。 傳聞我的和親對象是個(gè)殘疾皇子邪意,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評論 2 355

推薦閱讀更多精彩內(nèi)容