1、打開nginx官網,地址:http://nginx.org/en/download.html
2、使用wget命令下載所需要的包,這里使用 Stable版的 nginx-1.20.1 這個包。
>wget http://nginx.org/download/nginx-1.20.1.tar.gz
3、解壓這個包。
> tar -zxvf nginx-1.20.1.tar.gz
4、cd 進入 nginx-1.20.1 目錄,然后執行configure編譯命令, --prefix=/usr/local/nginx 表示nginx安裝的目錄
>./configure --prefix=/usr/local/nginx
執行后報錯,缺少PCRE庫,如圖:
5、安裝PCRE庫前要安裝C++ 的環境,兩個命令如下。
>yum install gcc-c++
>yum install -y pcre pcre-devel
同時把zlib庫和openssl都安裝一下,nginx使用zlib對http包的內容進行gzip,https協議需要openssl的支持。
>yum install -y zlib zlib-devel
>yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
6、安裝完成后再次編譯。這一次通過網上查閱資料,增加了編譯時候的參數設置。
>命令如下 ,/*注意這里 \ 表示命令還沒有輸入完,換行的意思。*/
>./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module
或者不指定臨時文件的存放目錄:使用下面的這個命令:
> ./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
編譯成功結果:
由於編譯時候指定把臨時文件放在了/var/temp/nginx中, 所以級聯建立temp文件夾和其下的nginx文件夾,-P 表示級聯創建,命令如下:
>mkdir /var/temp/nginx -p
7、編譯成功后,開始安裝,沒有報錯表示安裝成功。
> make && make install
成功后進入安裝目錄:
8、進入 sbin目錄啟動nginx