centOS7源碼編譯安裝Nginx

1、下載Nginx

在Nginx官網http://nginx.org/en/download.html選擇需要的Nginx版本,
然後複製地址進行下載

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

2、安裝編譯環境

安裝C/C++環境

yum install gcc

yum install gcc-c++ libstdc++-devel

3、編譯源碼

–prefix 參數指定安裝目錄,可以通過./configure --help 查看更多nginx編譯時的參數

[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/soft/nginx/  
  • 如果安裝過程出現如下錯誤:
nginx error: the HTTP rewrite module requires the PCRE library.

安裝pcre-devel解決

yum -y install pcre-devel
  • 上面的錯誤解決之後,如果出現如下錯誤
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解決:

yum -y install openssl openssl-devel

編譯成功後輸出Nginx運行目錄、配置等信息
在這裏插入圖片描述

3、編譯安裝

[root@localhost nginx-1.16.1]# make && make install

成功後會生成nginx二進制文件,在源碼目錄的objs目錄下
在這裏插入圖片描述

4、常用命令

進入到nginx的安裝目錄的sbin文件夾

  • 啓動/重新加載
./nginx -s reload

啓動的時候可能會報這個錯誤:

nginx: [error] invalid PID number "" in "/run/nginx.pid"

遇到上面的錯需要先執行:

./nginx -c /usr/soft/nginx/conf/nginx.conf

參數-c表示使用指定的配置文件

  • 停止
./nginx -s quit  #優雅的停止
./nginx -s stop  #立即停止
  • 查看Nginx版本
./nginx -v  # Nginx 安裝的版本
./nginx -V  #Nginx 編譯時各種參數信息
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章