跳转至

2. 安装

1. 官网

nginx.com   # 商业版
nginx.org   # 开源版
tengine.taobao.org  # 淘宝开发

2. 软件安装方法

# yum,最简单
# 二进制包,开箱即用
# 源码包,安装相对麻烦
# rpm包,直接rpm命令安装,根据rpm作者安装软件,不够自由。可以自己制作rpm包(待尝试!)
...

1. yum安装

# yum安装,最简单,直接一条命令即可!会自动解决依赖
yum install nginx -y

2. 二进制包

# 二进制包,解压后即用,就像windows中的绿色软件,下载后即可使用,不必安装,用完删除即可!
# 比如mysql的二进制包安装,直接解压缩,然后添加环境变量即可!
tar -zxvf mysql-5.7.20.tar.gz

3. 源码包

# 源码包,安装麻烦,需要自己解决依赖,但可根据需要安装模块及定制第三方功能
#1. 下载源码包
cd /opt
wget https://nginx.org/download/nginx-1.21.6.tar.gz

#2. 解压缩
tar -zxvf nginx-1.21.6

#3. 查看目录组成
root@baiduyun:/opt# cd nginx-1.21.6/
root@baiduyun:/opt/nginx-1.21.6# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
root@baiduyun:/opt/nginx-1.21.6#
root@baiduyun:/opt/nginx-1.21.6# ll
total 832
drwxr-xr-x  8 1001 1001   4096 Jan 25 23:04 ./
drwxr-xr-x 12 root root   4096 Feb 16 08:33 ../
drwxr-xr-x  6 1001 1001   4096 Feb 16 08:33 auto/         # 检测系统模块依赖信息
-rw-r--r--  1 1001 1001 316961 Jan 25 23:04 CHANGES       # 存放nginx变更日志
-rw-r--r--  1 1001 1001 484308 Jan 25 23:03 CHANGES.ru    
drwxr-xr-x  2 1001 1001   4096 Feb 16 08:33 conf/         # 配置文件信息
-rwxr-xr-x  1 1001 1001   2590 Jan 25 23:03 configure*    # 释放编译文件的可执行脚本
drwxr-xr-x  4 1001 1001   4096 Feb 16 08:33 contrib/      # 提供vim插件,使配置文件有颜色区分
drwxr-xr-x  2 1001 1001   4096 Feb 16 08:33 html/         # 存放html文件
-rw-r--r--  1 1001 1001   1397 Jan 25 23:03 LICENSE
drwxr-xr-x  2 1001 1001   4096 Feb 16 08:33 man/
-rw-r--r--  1 1001 1001     49 Jan 25 23:03 README
drwxr-xr-x  9 1001 1001   4096 Feb 16 08:33 src/          # 存放nginx源代码

#4. 查看编译帮助信息,命令如何使用,可以添加哪些模块功能
./configure --help

#5. 开始编译三部曲
# 1. 第一曲
./configure --prefix=/opt/demo/nginx --add-module=/home/fastdfs-nginx-module/src  --with-http_stub_status_module --with-http_ssl_module
参数说明:
    --prefix 用于指定nginx编译后的安装目录
    --add-module 为添加的第三方模块,此次添加了fdfs的nginx模块
    --with..._module 表示启用的nginx模块,如此处启用了http_ssl_module模块
可能出现的错误:
    出现:./configure:  error: the HTTP rewrite module requires the PCRE library.
    解决方法:yum -y install pcre-devel
    出现:SSL modules require the OpenSSL library
    解决方法:yum install openssl-devel
# 2. 第二曲
make

# 3. 第三曲
make install

3. 我的演示

apt安装

# 我是ubuntu系统,使用apt安装(与yum基本一样!)
apt install nginx -y

最后更新: 2022-02-20 13:32:53