1.本步骤只适用于centos8 首先查看自己的版本: 对号入座
cat /etc/redhat-release
2.安装编译工具及库文件
- 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
3.安装PCRE(作用:让 Nginx 支持 Rewrite 功能
)
yum install -y pcre pcre-devel
4.下载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]
5.解压
[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.编译安装
- 指定编译安装目录 --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版本
/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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。