centos7.6離線安裝nginx


nginx需要的依賴包括:gcc、g++、ssl、pcre、zlib;

一、准備階段


1、查看 操作系統是否安裝 gcc、gcc-c++;
2、從 CentOS 7 鏡像中,提取依賴安裝包:gcc、gcc-c++;
3、下載Nginx需要依賴的離線安裝包:ssl、pcre、zlib;
4、下載Nginx離線安裝包:nginx-1.18.0.tar.gz。

二、安裝步驟

1、安裝依賴:gcc、gcc-c++、ssl、pcre、zlib。注意:一定要先安裝gcc,再安裝gcc-c++。然后再安裝其他,其他的沒有先后順序。
2、安裝Nginx;
3、啟動Nginx(直接用默認配置啟動測試即可)。

三、詳細步驟

1、查看是否安裝 gcc 

gcc -v

(如果已經安裝 gcc ,忽略此步驟。)在 CentOS 7 的安裝鏡像,packages 目錄,找到安裝 gcc 相關的 rpm 包,並放到一個文件夾里(命名1),列表如下(注意:不同版本的操作系統,對應的rpm版本也不同):

 

 2、查看是否安裝 gcc-c++ 

gcc-c++ -v

(如果已經安裝 gcc-c++ ,忽略此步驟。)在 CentOS 7 的安裝鏡像,packages 目錄,找到安裝 gcc-c++ 相關的 rpm 包,並放到一個文件夾里(命名2),列表如下(注意:不同版本的操作系統,對應的rpm版本也不同):

 

3、下載Nginx需要依賴的離線安裝包,放到一個文件夾里(命名3)。下載地址如下:

https://www.openssl.org/source/openssl-1.1.0i.tar.gz
https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz
http://www.zlib.net/zlib-1.2.11.tar.gz

注:默認放在/usr/local/src目錄下

4、下載Nginx離線安裝包,放到文件夾1、2、3的同級目錄:
http://nginx.org/download/nginx-1.18.0.tar.gz

四、安裝

1、安裝 gcc (如果已經安裝 gcc ,忽略此步驟。)
進入到文件夾1

 rpm -Uvh *.rpm --nodeps --force

2、安裝 gcc-c++ (如果已經安裝 gcc-c++ ,忽略此步驟。)
進入到文件夾2

rpm -Uvh *.rpm --nodeps --force

 3、解壓並安裝 pcre 

cd /usr/local/src

tar -zxvf pcre-8.37.tar.gz -C /usr/local
cd /usr/local/pcre-8.37 

.
/configure

make

make install

 4、解壓並安裝zlib

cd /usr/local/src

tar -zxvf zlib-1.2.11.tar.gz -C /usr/local
cd /usr/local/zlib-1.2.11 

.
/configure

make

make install

 5、解壓並安裝 openssl 

cd /usr/local/src

tar -zxvf openssl-1.1.0i.tar.gz -C /usr/local

cd /usr/local/openssl-1.1.0i ./config

make

make install

 6、解壓並安裝 Nginx 

cd /usr/local/src

tar -zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=/usr/local/pcre-8.37 --with-zlib=/usr/local/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.1.0i
make

make install

--prefix=path

defines a directory that will keep server files. This same directory will also be used for all relative paths set by configure (except for paths to libraries sources) and in the nginx.conf configuration file. It is set to the /usr/local/nginx directory by default.

--with-pcre=path

sets the path to the sources of the PCRE library. The library distribution (version 4.4 — 8.43) needs to be downloaded from the PCRE site and extracted. The rest is done by nginx’s ./configure and make. The library is required for regular expressions support in the location directive and for the ngx_http_rewrite_module module.

--with-zlib=path

sets the path to the sources of the zlib library. The library distribution (version 1.1.3 — 1.2.11) needs to be downloaded from the zlib site and extracted. The rest is done by nginx’s ./configure and make. The library is required for the ngx_http_gzip_module module.

7、啟動Nginx(直接用默認配置啟動測試即可)

cd /usr/local/nginx/sbin
.
/nginx

8、開放端口

默認防火牆應該都是開啟的,因此需要開放端口。如果防火牆未開啟,以下步驟忽略。

查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)

firewall-cmd --state

開放nginx默認使用的80端口,並重啟防火牆

firewall-cmd --query-port=80/tcp

firewall-cmd --permanent --add-port=80/tcp

service firewalld restart

9、測試

瀏覽器打開,輸入IP地址即可,默認使用80端口。

10、查看Nginx進程

ps -ef|grep nginx

11、停止Nginx

./nginx -s stop

五、參考

1、https://blog.csdn.net/achi010/article/details/106392040

2、https://blog.csdn.net/MyMBS/article/details/90719902

3、https://www.cnblogs.com/hanzhi/articles/11482263.html

           4、http://nginx.org/en/docs/configure.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM