您的位置:首页 > 运维架构 > Nginx

CentOS 6.5 源码安装nginx 1.12.2

2018-02-05 18:06 489 查看
环境: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:
c40d
"/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: