在Linux中安装nginx
下载并解压缩
- cd /usr/local/
- wget http://nginx.org/download/nginx-1.18.0.tar.gz
- tar -vxzf nginx-1.18.0.tar.gz
- cd nginx-1.18.0
[root@test_server1 ~]
[root@test_server1 ~]
[root@test_server1 local]
[root@test_server1 local]
--2022-04-12 17:41:11-- http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’
100%[===============================================================================================================================================================================================>] 1,039,530 53.7KB/s in 27s
2022-04-12 17:41:38 (38.3 KB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]
[root@test_server1 local]
[root@test_server1 local]
[root@test_server1 local]
安装依赖
- yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@test_server1 nginx-1.18.0]
[root@test_server1 nginx-1.18.0]
[root@test_server1 nginx-1.18.0]
Package pcre-8.42-4.el8.x86_64 is already installed.
Package zlib-1.2.11-17.el8.x86_64 is already installed.
Package openssl-1:1.1.1g-15.el8_3.x86_64 is already installed.
.......[忽略]
Complete!
[root@test_server1 nginx-1.18.0]
执行./configure脚本
- ./configure
- –prefix指定安装目录, 默认安装在/usr/local/nginx目录。换安装目录./configure --prefix=/usr/local/nginx1
[root@test_server1 nginx-1.18.0]
checking for OS
+ Linux 4.18.0-305.19.1.el8_4.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
......[忽略]
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile
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@test_server1 nginx-1.18.0]
编译并安装
[root@test_server1 nginx-1.18.0]
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx-1.18.0'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/ngx_log.o \
src/core/ngx_log.c
......[忽略]
test ! -f '/usr/local/nginx/sbin/nginx' \
|| mv '/usr/local/nginx/sbin/nginx' \
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
......[忽略]
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/usr/local/nginx-1.18.0'
[root@test_server1 nginx-1.18.0]
建立链接,启动nginx,验证
- 在/usr/local/nginx/sbin目录下
- ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx ## 建立链接
- 执行./nginx
[root@test_server1 nginx-1.18.0]
[root@test_server1 local]
[root@test_server1 nginx]
total 16
drwxr-xr-x 2 root root 4096 Apr 12 18:00 conf
drwxr-xr-x 2 root root 4096 Apr 12 18:00 html
drwxr-xr-x 2 root root 4096 Apr 12 18:00 logs
drwxr-xr-x 2 root root 4096 Apr 12 18:00 sbin
[root@test_server1 nginx]
[root@test_server1 sbin]
[root@test_server1 sbin]
- 打开浏览器输入ip地址回车,(默认监听的是80端口,所以无需输入端口号)
- 看到Welcome to nginx!字样即成功
![在这里插入图片描述](https://img-blog.csdnimg.cn/6af0922978ad46dba128b869139bb735.png)
- 至此,nginx安装完成