1.本步骤只适用于centos8 首先查看本身的版本: 对号入座nginx
cat /etc/redhat-release
2.安装编译工具及库文件c++
执行命令:centos
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
3.安装PCRE(做用:让 Nginx 支持 Rewrite 功能
)app
yum install -y pcre pcre-devel
4.下载nginxcurl
稳定版下载地址: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]
5.解压url
[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]#
6.编译安装spa
SSL模块 --with-http_ssl_module模块code
[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版本ip
/home/work/nginx/sbin/nginx -v
7.配置systemctl 管理
[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启动 /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
问题
make install可能报错 是由于 安装的路径不是一个空的文件夹
这个时候须要把编译的路径设置为一个空的文件夹
./configure --prefix="空的文件夹路径" --with-http_stub_status_module --with-http_ssl_module
再从新执行以上流程便可.
最后看一下效果:
systemctl status nginx.service
curl 127.0.0.1