1. 程式人生 > >【Nginx】安裝

【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版本資訊如下:



[[email protected] ~]# 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

[[email protected] 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

[[email protected] zlib-1.2.11]# ./configure

[[email protected] zlib-1.2.11]# make

[[email protected] zlib-1.2.11]# make install

  2、pcre原始碼安裝:

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

  下載PCRE最新版本8.42原始碼:

1

wget  https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz

  解壓並進入PCRE程式碼根目錄:

1

2

[[email protected] ~]# tar zxvf pcre-8.42.tar.gz

[[email protected] ~]# cd pcre-8.42

  配置、編譯、安裝:

1

2

3

[[email protected] pcre-8.42]# ./configure

[[email protected] pcre-8.42]# make

[[email protected] pcre-8.42]# make  install

  檢視版本

1

2

[[email protected] 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

[[email protected] ~]# tar zxvf openssl-1.0.2o.tar.gz

[[email protected] ~]# cd openssl-1.0.2o

  配置、編譯、安裝:

1

2

3

[[email protected] openssl-1.0.2o]# ./config

[[email protected] openssl-1.0.2o]# make

[[email protected] 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

[[email protected] ~]# tar zxvf nginx-1.14.0.tar.gz

[[email protected] ~]# cd nginx-1.14.0

配置:

1

[[email protected] 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

[[email protected] nginx-1.14.0]# make

[[email protected] nginx-1.14.0]# make install

檢查nginx.conf配置正確性:

1

2

3

[[email protected] 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

[[email protected] 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

[[email protected] ~]# chmod 755 /etc/rc.d/rc.local

[[email protected] ~]# vim /etc/rc.d/rc.local