关于nginx:centos-8-のnginx安装步骤

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理