在Linux中安装nginx

在Linux中安装nginx

  • 环境 CentOS 7.X
  • nginx-1.18

下载并解压缩

  • 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 ~]# cd /usr/local
[root@test_server1 local]# 
[root@test_server1 local]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--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]# tar -vxzf nginx-1.18.0.tar.gz
[root@test_server1 local]# cd nginx-1.18.0

安装依赖

  • 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]# yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
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]# ./configure 
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]# 

编译并安装

  • make && make install
[root@test_server1 nginx-1.18.0]# make && make install
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]# cd ..
[root@test_server1 local]# cd nginx
[root@test_server1 nginx]# ll
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]# cd sbin
[root@test_server1 sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
[root@test_server1 sbin]# ./nginx # 启动nginx
- 打开浏览器输入ip地址回车,(默认监听的是80端口,所以无需输入端口号)
- 看到Welcome to nginx!字样即成功
![在这里插入图片描述](https://img-blog.csdnimg.cn/6af0922978ad46dba128b869139bb735.png)
- 至此,nginx安装完成
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值