实战Linux CentOS7 安装LNMP环境架构过程之编译nginx

首先 安装Development Tools工具包,这个工具包包括了GCC/GUN....等编译器和库,方便以后编译nginx,命令如下
<pre>
yum groupinstall "Development Tools"
</pre>
其中 groupinstall 是安装多个软件包

安装好后 开始安装nginx 打开官网http://www.nginx.org/ 选择Stable version 稳定版 复制下载链接之后 执行以下命令
<pre>
wget http://nginx.org/download/nginx-1.10.2.tar.gz
</pre>
我是先进入/home/jiaruo/Downloads/目录之后 在进行wget下载的,把nginx包下载到/home/jiaruo/Downloads/这个目录 wget是个下载工具 支持http https ftp 这三种协议下载
执行ls 命令 查看包是否下载完毕
<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>
解压命令自行百度,我也不太会,
执行ls命令查看解压后的文件夹
<pre>
[root@localhost Downloads]# ls
nginx-1.10.2 nginx-1.10.2.tar.gz
[root@localhost Downloads]#
</pre>
进入文件夹 并且查看文件
<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这个文件,configure脚本配置工具就是基础之一,具体的自行百度,我们先来编译,命令如下
<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模块 ,你可以禁止也可以安装,咋安装,不会 百度,的出来结果 去ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 这里下载,好吧 ,那我就下载,我们回到上级目录 就是/home/jiaruo/Downloads/目录 然后执行命令
<pre>
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
</pre>
下载完毕之后ls 查看文件是否存在 如果不存在 请重换资源下载 如果还不轻,请拿起你的砖头砸电脑
我这里下载完毕 pcre-8.38.tar.gz 执行解压命令
<pre>tar xvf pcre-8.38.tar.gz </pre>
执行ls命令可以看出多了个pcre开头的文件夹 我们进入文件夹内进行编译
<pre>
./configure --prefix=/usr/local/pcre
</pre>
编译完毕 执行 make && make install 命令,configure会在你的系统上测试存在的特性,make是编译的意思, make install是安装的意思,意思当make没出错的时候 就执行安装
<pre>make && make install</pre>
好了,安装完毕之后我们返回上一级 进入nginx的文件夹,然后继续编译,在上次测试的时候告诉我们了 缺少pcre模块 如果安装的话使用 --with-pcre=目录 进行安装,这个目录是指源码目录 不是安装目录,我在这个坑里待了2天,执行以下命令
<pre>
./configure --prefix=/usr/local/nginx --with-pcre=/home/jiaruo/Downloads/pcre2-10.20
</pre>
./configure --prefix=你要安装在哪里 --with-pcre=pcre解压出来的目录
完事之后 尼玛又报错
<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的下载目录,找不到 然后百度得出结果http://www.zlib.net/zlib-1.2.8.tar.gz
继续回到下载文件存档的目录,下载完毕执行解压,还需要我重复么,重复一次吧
<pre>
tar xvf zlib-1.2.8.tar.gz
</pre>
解压后 会得到zlib-1.2.8 文件夹,进入 然后编译
<pre>./configure --prefix=/usr/local/zlib</pre>
编译完成 继续进入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>
老天保佑,在出错我就不装了
...
...
...
<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>
出现上面的内容说明测试通过可以编译和安装
嘿 真特么好使 继续编译 && 安装
<pre>make && make install</pre>
...
...
...
出先错误<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>
然后请教了下冯立松大神,发现是之前pcre版本问题 之前装的是pcre2 已更正 然后 在重复pcre编译之后 在进到nginx 下面执行
<pre>
./configure --prefix=/usr/local/nginx \

--with-pcre=/home/jiaruo/Downloads/pcre-8.38 \
--with-zlib=/home/jiaruo/Downloads/zlib-1.2.8

</pre>
没错误 然后继续 编译 安装
<pre>make && make install</pre>
没发现错误,然后试试安装成功 进入目录试试
<pre>
cd /usr/local/nginx/
</pre>
顺利进来 ls一下 发现有个conf 顾名思义 里面放的都是配置文件夹里面有个nginx.conf 就是主配置文件
我们进入返回nginx根目录 进入sbin目录 发现有个nginx 执行
<pre>./nginx</pre>
没抱任何错误的话 说明启动成功 我们查看进程
<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(控制进程) 和worker(服务进程)都在运行中,说明启动成功,
在外网访问ip,尼玛 怎么报错,怎么怎么,恩 防火墙,应该是这货搞得鬼
给我"沙特当" 命令如下<pre>service iptables stop</pre>看到什么玩意ok 说明关闭成功 再次 访问 恩 访问成功


QQ20161021-0.png

nginx安装完毕 撸代码去

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,108评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,699评论 1 296
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,812评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,236评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,583评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,739评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,957评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,704评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,447评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,643评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,133评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,486评论 3 256
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,151评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,108评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,889评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,782评论 2 277
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,681评论 2 272

推荐阅读更多精彩内容