CentOS 7 安裝nginx詳細

安裝編譯工具及庫文件

注:本次默認文件下載目錄在/opt/nginx/。

一. 依賴安裝,如果是新環境需要安裝gcc gcc-c++ make,GCC——GNU編譯器集合(GCC可以使用默認包管理器的倉庫(repositories)來安裝,包管理器的選擇依賴於你使用的Linux發佈版本,包管理器有不同的實現:yum是基於Red Hat的發佈版本;apt用於Debian和Ubuntu;yast用於SuSE Linux等等。)

​yum install -y gcc gcc-c++ make

二. OpenSSL 安裝
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。
nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫。

wget https://www.openssl.org/source/openssl-1.1.1.tar.gz
tar zxvf openssl-1.1.1.tar.gz

三. zlib 安裝
zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫。

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxvf zlib-1.2.11.tar.gz

四. PCRE pcre-devel 安裝
PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也需要此庫。

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

五. Nginx的安裝包

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

Nginx安裝配置

進入nginx-1.14.0目錄並執行

cd /opt/nginx/nginx-1.14.0
./configure --user=nobody --group=nobody --prefix=/opt/nginx/nginx-1.14.0 --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with-pcre=/opt/nginx/pcre-8.33 --with-zlib=/opt/nginx/zlib-1.2.11 --with-openssl=/opt/nginx/openssl-1.1.1
make && make install

–with-pcre=/opt/nginx/pcre-8.33

–with-zlib=/opt/nginx/zlib-1.2.11

–with-openssl=/opt/nginx/openssl-1.1.1

分別指其相應源碼目錄,即剛剛解壓得到的目錄,需要根據自己實際情況修改。、

到此,nginx安裝完成;

默認日誌路徑爲/opt/nginx/nginx-1.14.0/logs/,但是默認沒有創建logs目錄,因此需要手動創建logs目錄,否則啓動時會報錯。

mkdir /opt/nginx/nginx-1.14.0/logs

停止啓動nginx

/opt/nginx/nginx-1.14.0/sbin
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload

./nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
./nginx -s stop:此方式相當於先查出nginx進程id再使用kill命令強制殺掉進程。

開機自啓動

在rc.local增加“/opt/nginx/nginx-1.14.0/sbin/nginx”就可以了。

vi /etc/rc.local

在這裏插入圖片描述
設置執行權限:

cd /etc/
chmod 755 rc.local

參考連接

  1. https://blog.csdn.net/fukai8350/article/details/80634566
  2. https://blog.csdn.net/qq_38591756/article/details/82829902
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章