Nginx 是世界上最受欢迎的 Web 服务器之一,负责托管互联网上一些最大和流量最高的站点。 这是一个轻量级的选择,可以用作 Web 服务器或反向代理。在公司内部,像Zabbix、ELK都可以通过Nginx实现Web端的管理。
接下来,我将在 Ubuntu 20.04 服务器上安装 Nginx,创建自签名证书,设定访问https跳转,保障内网客户端浏览器与Web服务器之间的通讯安全。
- VM环境:
┌──────────────────────────────────────────────────────────────────────┐
│ • MobaXterm Personal Edition v21.2 • │
│ (SSH client, X server and network tools) │
│ │
│ ➤ SSH session to testuser@192.168.226.131 │
│ • Direct SSH : ✔ │
│ • SSH compression : ✔ │
│ • SSH-browser : ✔ │
│ • X11-forwarding : ✔ (remote display is forwarded through SSH) │
│ │
│ ➤ For more info, ctrl+click on help or visit our website. │
└──────────────────────────────────────────────────────────────────────┘
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-91-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sat 04 Dec 2021 02:32:23 PM UTC
System load: 0.06 Processes: 161
Usage of /: 25.3% of 23.74GB Users logged in: 1
Memory usage: 6% IPv4 address for ens192: 192.168.226.131
Swap usage: 0%
- 所有源码安装包存放目录
/home/testuser/source
- 安装方式:
从源代码编译和安装
从源代码编译 NGINX 比预构建的包提供更多的灵活性:可以添加特定模块(来自 NGINX 或第三方),并应用最新的安全补丁。
- 安装编译工具
sudo apt-get update
sudo apt-get install build-essential
- 安装 NGINX 依赖包
在从源代码编译 NGINX Open Source 之前,需要为其依赖项安装库:
- PCRE——支持正则表达式,NGINX Core和Rewrite模块需要。
$ wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
$ tar -zxf pcre-8.45.tar.gz
$ cd pcre-8.45
$ ./configure
$ make
$ sudo make install
- zlib – 支持头压缩,NGINX Gzip模块需要。
$ wget http://zlib.net/zlib