Centos8安裝Nginx1.18.0

介紹

Nginx(“engine x”)是一款是由俄羅斯的程序設計師Igor Sysoev所開發高性能的 Web和 反向代理 服務器,也是一個 IMAP/POP3/SMTP 代理服務器。
在高連接併發的情況下,Nginx是Apache服務器不錯的替代品。
最新穩定版: nginx-1.18.0

Nginx 依賴 安裝

安裝編譯工具及庫文件

  • make gcc-c++ 編譯使用
  • zlib zlib-devel nginx中gzip使用
  • openssl openssl-devel nginx支持 https使用(即在ssl協議上傳輸http)

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

[root@localhost ~]# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
Installed:
  gcc-c++-8.3.1-4.5.el8.x86_64                          libtool-2.4.6-25.el8.x86_64                       
  openssl-devel-1:1.1.1c-2.el8_1.1.x86_64               zlib-devel-1.2.11-10.el8.x86_64                   
  autoconf-2.69-27.el8.noarch                           automake-1.16.1-6.el8.noarch                      
  libstdc++-devel-8.3.1-4.5.el8.x86_64                  emacs-filesystem-1:26.1-5.el8.noarch              
  keyutils-libs-devel-1.5.10-6.el8.x86_64               krb5-devel-1.17-9.el8.x86_64                      
  libcom_err-devel-1.44.6-3.el8.x86_64                  libkadm5-1.17-9.el8.x86_64                        
  libselinux-devel-2.9-2.1.el8.x86_64                   libsepol-devel-2.9-1.el8.x86_64                   
  libverto-devel-0.3.0-5.el8.x86_64                     m4-1.4.18-7.el8.x86_64                            
  pcre2-devel-10.32-1.el8.x86_64                        pcre2-utf16-10.32-1.el8.x86_64                    
  pcre2-utf32-10.32-1.el8.x86_64                       

Complete!

首先要安裝 PCRE

PCRE 作用是讓 Nginx 支持 Rewrite 功能。

[root@localhost ~]# yum install -y pcre pcre-devel

Installed:
  pcre-devel-8.42-4.el8.x86_64        pcre-cpp-8.42-4.el8.x86_64        pcre-utf16-8.42-4.el8.x86_64       
  pcre-utf32-8.42-4.el8.x86_64       

Complete!
[root@localhost ~]# pcre-config --version
8.42
[root@localhost ~]# 

安裝 Nginx

下載 Nginx

穩定版下載地址:http://nginx.org/download/nginx-1.18.0.tar.gz

[root@localhost ~]# mkdir /home/work/nginx
[root@localhost ~]# cd /home/work/nginx/
[root@localhost nginx]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-05-26 23:42:49--  http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’

nginx-1.18.0.tar.gz        100%[=======================================>]   1015K  8.40KB/s    in 2m 3s   

2020-05-26 23:44:53 (8.27 KB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]

解壓安裝包

[root@localhost nginx]# tar zxf nginx-1.18.0.tar.gz 
[root@localhost nginx]# ll
total 1016
drwxr-xr-x 8 1001 1001     158 Apr 21 22:09 nginx-1.18.0
-rw-r--r-- 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz
[root@localhost nginx]# 

編譯安裝

  • 指定編譯安裝目錄 --prefix=/home/work/nginx
  • 監控模塊 --with-http_stub_status_module
  • SSL模塊 --with-http_ssl_module模塊
[root@localhost nginx]# cd nginx-1.18.0
[root@localhost nginx-1.18.0]# ./configure --prefix=/home/work/nginx --with-http_stub_status_module --with-http_ssl_module 

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/home/work/nginx"
  nginx binary file: "/home/work/nginx/sbin/nginx"
  nginx modules path: "/home/work/nginx/modules"
  nginx configuration prefix: "/home/work/nginx/conf"
  nginx configuration file: "/home/work/nginx/conf/nginx.conf"
  nginx pid file: "/home/work/nginx/logs/nginx.pid"
  nginx error log file: "/home/work/nginx/logs/error.log"
  nginx http access log file: "/home/work/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"



[root@localhost nginx-1.18.0]# make
[root@localhost nginx-1.18.0]# make install

查看nginx版本

[root@localhost nginx-1.18.0]# /home/work/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

Nginx 其他命令

  • 啓動 /home/work/nginx/sbin/nginx
  • 重載配置文件 /home/work/nginx/sbin/nginx -s reload
  • 重啓 /home/work/nginx/sbin/nginx -s reopen
  • 停止 /home/work/nginx/sbin/nginx -s stop
[root@localhost nginx-1.18.0]#  /home/work/nginx/sbin/nginx
[root@localhost nginx-1.18.0]#  /home/work/nginx/sbin/nginx -s stop
[root@localhost nginx-1.18.0]# 

配置systemctl 管理

創建 nginx.service

[root@localhost ~]# vi /etc/systemd/system/nginx.service
[root@localhost ~]# 
[root@localhost ~]# cat /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=oneshot
ExecStart=/home/work/nginx/sbin/nginx
ExecStop=/home/work/nginx/sbin/nginx -s stop 
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

[root@localhost ~]# 

  • 啓動 systemctl start nginx
  • 停止 systemctl stop nginx
  • 狀態 systemctl status nginx
  • 打開開機自啓 systemctl enable nginx
  • 關閉開機自啓 systemctl disable nginx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章