Nginx 学习笔记
一、Nginx 简介
1. Nginx 是什么?
Nginx (engine x) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器 Nginx 可以作为一个 Web 服务器进行网站的发布,也可以作为反向代理服务器进行负载均衡的实现常见的 Web 服务器:Tomcat、Apache、Nginx、Weblogic 等
顺哥轻创
2. 特点
占用内存少、并发能力强
二、搭建 Nginx 环境
1. 安装 nginx
两种方式:
- 源代码安装:需要编译
./configure
——>make
——>make install
- 在线安装,参考:
http://nginx.org/en/linux_packages.html
在线安装 (这里以 Ubuntu 为例子):
Install the prerequisites:
BASH
sudo apt install curl gnupg2 ca-certificates lsb-release |
To set up the apt repository for stable nginx packages, run the following command:
BASH
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list |
If you would like to use mainline nginx packages, run the following command instead:
BASH
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list |
Next, import an official nginx signing key so apt could verify the packages authenticity:
BASH
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - |
Verify that you now have the proper key:
BASH
sudo apt-key fingerprint ABF5BD827BD9BF62 |
The output should contain the full fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 as follows:
BASH
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 uid [ unknown] nginx signing key <signing-key@nginx.com> |
To install nginx, run the following commands:
BASH
sud |