CentOS 6.5 源码安装nginx 1.12.2

环境:CentOS 6.5 64bit


nginx官网介绍配置安装:http://nginx.org/en/docs/configure.html


一、安装nginx依赖的软件

nginx是C写的,需要用GCC编译;nginx中的rewrite module需要PCRE;nginx中的gzip module需要zlib;nginx中的HTTP SSL module需要OpenSSL。

已安装的GCC版本信息如下:

[root@szdev03 stalker]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

1)zlib源码安装:

zlib下载官网:http://www.zlib.net/

下载zlib最新版本1.2.11源码:

[root@szdev03 stalker]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
解压并进 zlib代码根目录:

[root@szdev03 stalker]# tar zxvf zlib-1.2.11.tar.gz
[root@szdev03 stalker]# cd zlib-1.2.11
配置、编译、安装:

[root@szdev03 zlib-1.2.11]# ./configure
[root@szdev03 zlib-1.2.11]# make
[root@szdev03 zlib-1.2.11]# make install
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.so.1.2.11 /usr/local/lib
chmod 755 /usr/local/lib/libz.so.1.2.11
rm -f /usr/local/share/man/man3/zlib.3
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
rm -f /usr/local/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
[root@szdev03 zlib-1.2.11]# whereis zlib
zlib: /usr/include/zlib.h /usr/share/man/man3/zlib.3.gz

2)PCRE源码安装:

PCRE官网:http://www.pcre.org/

下载PCRE最新版本8.41源码:

[root@szdev03 stalker]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
解压并进PCRE代码根目录:

[root@szdev03 stalker]# tar zxvf pcre-8.41.tar.gz
[root@szdev03 stalker]# cd pcre-8.41
配置、编译、安装:

[root@szdev03 pcre-8.41]# ./configure
[root@szdev03 pcre-8.41]# make
[root@szdev03 pcre-8.41]# make install
查看版本:

[root@szdev03 pcre-8.41]# pcre-config --version
8.41
说明安装成功。

3)OpenSSL源码安装:

OpenSSL官网:https://www.openssl.org/

下载OpenSSL版本1.0.2n源码:

[root@szdev03 stalker]# wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
解压并进入openssl代码根目录:

[root@szdev03 stalker]# tar zxvf openssl-1.0.2n.tar.gz
[root@szdev03 stalker]# cd openssl-1.0.2n
配置、编译、安装:

[root@szdev03 openssl-1.0.2n]# ./config
[root@szdev03 openssl-1.0.2n]# make
[root@szdev03 openssl-1.0.2n]# make install


二、源码安装nginx

下载nginx最新稳定版本1.12.2源码:

[root@szdev03 stalker]# wget wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压并进入nginx代码根目录:

[root@szdev03 stalker]# tar zxvf nginx-1.12.2.tar.gz
[root@szdev03 stalker]# cd nginx-1.12.2
配置:

[root@szdev03 nginx-1.12.2]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11
./configure之后的正确信息如下:

Configuration summary
  + using PCRE library: ../pcre-8.41
  + using system OpenSSL library
  + using zlib library: ../zlib-1.2.11

  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"

如果./configure提示OpenSSL找不到:

checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

按照提示说明,--with-openssl=<source path>即可。

[root@szdev03 nginx-1.12.2]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2n

这样就配置正确,信息如下:

Configuration summary
  + using PCRE library: ../pcre-8.41
  + using OpenSSL library: ../openssl-1.0.2n
  + using zlib library: ../zlib-1.2.11

  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"

编译安装:

[root@szdev03 nginx-1.12.2]# make
[root@szdev03 nginx-1.12.2]# make install


检查nginx.conf配置正确性:

[root@szdev03 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx:

[root@szdev03 ~]# /usr/local/nginx/sbin/nginx


浏览器登陆成功如下:



关闭nginx命令:

[root@szdev03 ~]# /usr/local/nginx/sbin/nginx -s stop
命令相关详见官网: http://nginx.org/en/docs/beginners_guide.html


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值