【Nginx】安装

author:咔咔

wechat:fangkangfk

安装时会出现什么异常

1.在第一次安装nginx时,使用make编译和make install安装时会安装不到usr/local/下,这个时候在编译一次即可

2.在./configure时,有的伙伴没有安装基础包出现的问题ivalid c++ compiler or c++ compiler flags,这个需要yum install -y gcc gcc-c++即可

3.主机ping不同虚拟机问题在其他文章写,关闭虚拟机防火墙即可

nginx最终的安装目录会在/usr/local/ngixn下

安装基础包

yum -y install gcc gcc-c++ lrzsz wget vim


一、安装nginx依赖的软件nginx官网介绍配置安装:http://nginx.org/en/docs/configure.html

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

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



[root@localhost ~]# gcc -v

Using built-in specs.

COLLECT_GCC=gcc

COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper

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-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux

Thread model: posix

gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)


  zlib下载官网:http://www.zlib.net/  1、zlib源码安装:

  下载zlib最新版本1.2.11源码:

1

[root@localhost plu]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz

  解压并进入zlib代码根目录:

1

2

tar zxvf zlib-1.2.11.tar.gz

cd zlib-1.2.11

  配置、编译、安装:

1

2

3

[root@localhost zlib-1.2.11]# ./configure

[root@localhost zlib-1.2.11]# make

[root@localhost zlib-1.2.11]# make install

  2、pcre源码安装:

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

  下载PCRE最新版本8.42源码:

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz

1

2

[root@localhost ~]# tar zxvf pcre-8.42.tar.gz

[root@localhost ~]# cd pcre-8.42

  解压并进入PCRE代码根目录:

  配置、编译、安装:

1

2

3

[root@localhost pcre-8.42]# ./configure

[root@localhost pcre-8.42]# make

[root@localhost pcre-8.42]# make  install

  查看版本

1

2

[root@localhost pcre-8.42]# pcre-config --version

8.42

  3、OpenSSL源码安装:

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

  下载OpenSSL版本1.0.2o源码:

1

wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz

  解压并进入openssl代码根目录:

1

2

[root@localhost ~]# tar zxvf openssl-1.0.2o.tar.gz

[root@localhost ~]# cd openssl-1.0.2o

  配置、编译、安装:

1

2

3

[root@localhost openssl-1.0.2o]# ./config

[root@localhost openssl-1.0.2o]# make

[root@localhost openssl-1.0.2o]# make install

  

二、源码安装nginx

nginx最新稳定版本1.14.0

1

wget http://nginx.org/download/nginx-1.14.0.tar.gz

解压并进入nginx代码根目录:

1

2

[root@localhost ~]# tar zxvf nginx-1.14.0.tar.gz

[root@localhost ~]# cd nginx-1.14.0

配置:

1

[root@localhost nginx-1.14.0]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2o

编译安装:

1

2

[root@localhost nginx-1.14.0]# make

[root@localhost nginx-1.14.0]# make install

检查nginx.conf配置正确性:

1

2

3

[root@localhost nginx-1.14.0]# /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

启动服务

1

[root@localhost nginx-1.14.0]# /usr/local/nginx/sbin/nginx

停止服务

1

/usr/local/nginx/sbin/nginx -s stop 

命令相关详见官网:http://nginx.org/en/docs/beginners_guide.html

设置开机自启动

1

2

[root@localhost ~]# chmod 755 /etc/rc.d/rc.local

[root@localhost ~]# vim /etc/rc.d/rc.local

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...