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