环境依赖包
zlib zlib-devel pcre pcre-devel
下载nginx安装包
1、下载nginx
[root@node01 ~]# wget http://nginx.org/download/nginx-1.24.0.tar.gz
--2023-07-18 16:49:00-- http://nginx.org/download/nginx-1.24.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1112471 (1.1M) [application/octet-stream]
Saving to: ‘nginx-1.24.0.tar.gz’
100%[===================================================>] 1,112,471 11.5KB/s in 69s
2023-07-18 16:50:14 (15.9 KB/s) - ‘nginx-1.24.0.tar.gz’ saved [1112471/1112471]
解压缩
2、解压缩
[root@node01 ~]# tar -zxf nginx-1.24.0.tar.gz
[root@node01 ~]# ll -h nginx-1.24.0
total 816K
drwxr-xr-x. 6 1001 1001 4.0K Jul 18 16:52 auto
-rw-r--r--. 1 1001 1001 316K Apr 11 09:45 CHANGES
-rw-r--r--. 1 1001 1001 483K Apr 11 09:45 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Jul 18 16:52 conf
-rwxr-xr-x. 1 1001 1001 2.6K Apr 11 09:45 configure
drwxr-xr-x. 4 1001 1001 72 Jul 18 16:52 contrib
drwxr-xr-x. 2 1001 1001 40 Jul 18 16:52 html
-rw-r--r--. 1 1001 1001 1.4K Apr 11 09:45 LICENSE
drwxr-xr-x. 2 1001 1001 21 Jul 18 16:52 man
-rw-r--r--. 1 1001 1001 49 Apr 11 09:45 README
drwxr-xr-x. 9 1001 1001 91 Jul 18 16:52 src
编译安装
[root@node01 ~]# cd nginx-1.24.0
[root@node01 nginx-1.24.0]# ./configure --prefix=/usr/local/nginx
[root@python nginx-1.24.0]# ./configure --prefix=/usr/local/nginx
checking for OS
+ Linux 3.10.0-1062.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
[root@python nginx-1.24.0]# yum install gcc* -y
再次编译报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
安装perl库
[root@node01 nginx-1.24.0]# yum install -y pcre pcre-devel
再次编译
[root@node01 nginx-1.24.0]# ./configure --prefix=/usr/local/nginx
再次报错
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
安装安装zlib库
[root@node01 nginx-1.24.0]# yum install -y zlib zlib-devel
编译成功
[root@node01 nginx-1.24.0]# ./configure --prefix=/usr/local/nginx
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/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@node01nginx-1.24.0]# make && make install
make[1]: Leaving directory `/root/nginx-1.24.0'
启动Nginx
启动nginx
[root@node01 nginx-1.24.0]# cd /usr/local/nginx/sbin/
[root@node01 sbin]# ./nginx
[root@node01 sbin]# ps -ef | grep nginx | grep -v grep
root 8393 1 0 17:10 ? 00:00:00 nginx: master process ./nginx
nobody 8394 8393 0 17:10 ? 00:00:00 nginx: worker process
./nginx -s stop 快速停止
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload 重新加载配置
放行80端口
[root@node01 sbin]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@node01 sbin]# firewall-cmd --reload
success
[root@node01 sbin]# nmap localhost
Starting Nmap 6.40 ( http://nmap.org ) at 2023-07-18 17:12 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000070s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 1.59 seconds
[root@node01 sbin]# netstat -anp | grep 80 | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8393/nginx: master
版本查询
[root@node01 ~]# /usr/local/nginx/sbin/nginx -version
nginx version: nginx/1.24.0