设为首页 收藏本站
查看: 659|回复: 0

[经验分享] CentOS 6.5 编译安装 nginx

[复制链接]

尚未签到

发表于 2018-11-14 06:16:35 | 显示全部楼层 |阅读模式
1.安装准备
  安装前准备好nginx编译安装需要使用的的pcre、zlib、openssl扩展库源码包及nginx的源码包,nginx的gzip模块需要zlib库,rewrite模块需要pcre库,ssl模块需要openssl库,可以从官网下载,也可以到我的网盘里下载,我的共享文件目录地址是:http://pan.baidu.com/s/1kTI8rVD
  共享的nginx安装包文件下载地址:http://pan.baidu.com/s/1kTI8rVD#dir/path=%2F%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%2Flinux%2Fnginx
2.安装
  (1)安装openssl库
[root@zhhuang-pc 下载]# tar zxvf openssl-fips-2.0.5.tar.gz  
[root@zhhuang-pc 下载]# cd openssl-fips-2.0.5
  
[root@zhhuang-pc openssl-fips-2.0.5]# ./config
  
[root@zhhuang-pc openssl-fips-2.0.5]# make
  
[root@zhhuang-pc openssl-fips-2.0.5]# make install
  查看是否安装成功,如果安装成功,会显示openssl安装成功的路径
[root@zhhuang-pc openssl-fips-2.0.5]# whereis openssl  
openssl: /usr/bin/openssl /usr/lib64/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz
  
[root@zhhuang-pc openssl-fips-2.0.5]#
  (2)安装zlib库
[root@zhhuang-pc 下载]# tar zxvf zlib-1.2.8.tar.gz  
[root@zhhuang-pc 下载]# cd zlib-1.2.8
  
[root@zhhuang-pc zlib-1.2.8]# ./configure
  
[root@zhhuang-pc zlib-1.2.8]# make
  
[root@zhhuang-pc zlib-1.2.8]# make install
  查看zlib是否安装成功,安装成功,可以看到zlib编译后库所在的目录
[root@zhhuang-pc zlib-1.2.8]# whereis zlib  
zlib: /usr/include/zlib.h /usr/share/man/man3/zlib.3.gz
  
[root@zhhuang-pc zlib-1.2.8]#
  (3)安装pcre库
[root@zhhuang-pc 下载]# tar zxvf pcre-8.34.tar.bz2  
[root@zhhuang-pc 下载]# cd pcre-8.34
  
[root@zhhuang-pc pcre-8.34]# ./configure
  
[root@zhhuang-pc pcre-8.34]# make
  
[root@zhhuang-pc pcre-8.34]# make install
  查看pcre是否安装成功,安装成功后会显示pcre编译库的安装路径
[root@zhhuang-pc pcre-8.34]# whereis pcre  
pcre: /usr/local/lib/pcre /usr/include/pcre.h /usr/local/pcre /usr/share/man/man3/pcre.3.gz
  
[root@zhhuang-pc pcre-8.34]#
  (4)安装nginx
  注意:--with-pcre后面的参数是pcre库解压后的源码路径,同理--with-openssl和--with-zlib后面的参数都是相关库源码包解压后的文件夹路径
  
[root@zhhuang-pc 下载]# tar zxvf nginx-1.5.4.tar.gz  
[root@zhhuang-pc 下载]# cd nginx-1.5.4
  
[root@zhhuang-pc nginx-1.5.4]# ./configure --with-pcre=/home/zhhuang/下载/pcre-8.34 --with-zlib=/home/zhhuang/下载/zlib-1.2.8 --with-openssl=/home/zhhuang/下载/openssl-fips-2.0.5
  
[root@zhhuang-pc nginx-1.5.4]# make
  
[root@zhhuang-pc nginx-1.5.4]# make install
  查看nginx是否安装成功,安装成功后显示nginx编译安装后的路径位置
[root@zhhuang-pc nginx-1.5.4]# whereis nginx  
nginx: /usr/local/nginx
  安装成功后,我们可以查看下nginx的版本
[root@zhhuang-pc sbin]# /usr/local/nginx/sbin/nginx -v  
nginx version: nginx/1.5.4
  
[root@zhhuang-pc sbin]#
  安装成功后,熟悉下nginx常用的命令,我们可以尝试显示编译选项和版本信息并退出
[root@zhhuang-pc sbin]# /usr/local/nginx/sbin/nginx -V  
nginx version: nginx/1.5.4
  
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
  
configure arguments: --with-pcre=/home/zhhuang/下载/pcre-8.34 --with-zlib=/home/zhhuang/下载/zlib-1.2.8 --with-openssl=/home/zhhuang/下载/openssl-fips-2.0.5
  
[root@zhhuang-pc sbin]#
  安装成功后,熟悉下nginx常用的命令
  /usr/local/nginx/sbin/nginx -V
  nginx命令参数说明:
  -?,-h: 显示帮助
  -v :显示版本信息并推出
  -V :显示编译选项及版本信息并推出
  -t :测试配置文件并退出
  -s signal     : send signal to a master process: stop, quit, reopen,>  -p prefix     : set prefix path (default: /opt/nginx-0.8.45/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
  -s参数之前是没有的,它有四个命令stop/quit/reopen/reload
  -c参数在手动启动nginx的时候会用到
  如下是nginx启动及查看nginx进程命令
[root@zhhuang-pc sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  
[root@zhhuang-pc sbin]# ps -aux|grep nginx
  
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
  
root     21772  0.0  0.0  22168   648 ?        Ss   19:22   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  
nobody   21773  0.0  0.0  22564  1176 ?        S    19:22   0:00 nginx: worker process
  
root     21775  0.0  0.0 103256   828 pts/1    S+   19:22   0:00 grep nginx
  
[root@zhhuang-pc sbin]#
  如下是nginx进程退出及退出后查看nginx进程发现nginx进程已关闭的命令操作
[root@zhhuang-pc sbin]# ps -aux|grep nginx  
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
  
root     21790  0.0  0.0 103256   824 pts/1    S+   19:24   0:00 grep nginx
  
[root@zhhuang-pc sbin]#
  重启nginx进程
[root@zhhuang-pc sbin]# /usr/local/nginx/sbin/nginx -s>
[root@zhhuang-pc sbin]#
3.名词解释
  (1)pcre(Perl Compatible Regular Expressions):perl语言兼容正则表达式,是一个使用c语言编写的正则表达式函数库,性能超过POSIX正则表达式函数库及其他一些经典的函数库,作者是菲利普-海泽。nginx处理http网络数据包时字符过滤需要使用这个正则表达式函数库。
  (2)openssl(secure socket layer):安全套接层协议,保证两个应用通信的可靠性和保密性,可在服务端和用户端同时实现支持,强大的安全套接字密码库,nginx和apach可以使用它来加密https通信。
  (3)zlib:提供支持数据压缩功能的函数库,nginx编译安装时指定他的源码目录,这样可以将zlib库编译到nginx中,这样nginx启动时就不用动态加载的方式去load,这种方式比动态加载有更高的效率。nginx可以使用zlib库压缩及解压使用http协议接收的gzip网络数据包。
  2014年4月3日16:53:40 于上海爱博家园三村
  the end



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-634681-1-1.html 上篇帖子: nginx的简介和基本配置 下篇帖子: 开启nginx目录文件列表显示功能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表