Skip to content

Commit 81f21e4

Browse files
committed
在Ubuntu 16.04中如何从源代码编译Nginx
1 parent 5f3f5cb commit 81f21e4

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Nginx/nginx-install.md

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
## 在Ubuntu 16.04中如何从源代码编译Nginx
22
+ NGINX可用作HTTP / HTTPS服务器,反向代理服务器,邮件代理服务器,负载均衡器,TLS终结器或缓存服务器。它是相当模块化的设计。它具有由社区创建的本机模块和第三方模块。以C编程语言编写,它是一个非常快速和轻便的软件。
3-
## 从源头构建NGINX的要求
4-
#### 强制性要求:
3+
#### 从源头构建NGINX的要求,强制性要求:
54
+ OpenSSL库版本介于1.0.2 - 1.1.0之间
65
+ Zlib库版本介于1.1.3 - 1.2.11之间
76
+ PCRE库版本在4.4 - 8.40之间
87
+ GCC编译器
98
#### 可选要求:
109
+ PERL
1110
+ LIBATOMIC_OPS
12-
+ 的libgd
11+
+ LibFD
1312
+ MaxMind GeoIP
1413
+ libxml2的
15-
+ 的libxslt
14+
+ libxslt
1615
#### 开始之前
1716
+ 创建普通用户`sudo`访问。
1817
+ 切换到新用户:`su - <username>`
1918
+ 更新系统:`sudo apt update && sudo apt upgrade -y`
2019
#### 从源代码构建NGINX
2120
+ 1、NGINX是用C编写的程序,所以我们需要安装C编译器(GCC)。
22-
`sudo apt install build-essential -y`
21+
```bash
22+
sudo apt install build-essential -y
23+
```
2324
+ 2、下载最新版本的NGINX源代码并解压缩:
24-
`wget https://nginx.org/download/nginx-1.13.1.tar.gz && tar zxvf nginx-1.13.1.tar.gz`
25+
```bash
26+
wget https://nginx.org/download/nginx-1.13.1.tar.gz && tar zxvf nginx-1.13.1.tar.gz
27+
```
2528
+ 3、下载NGINX依赖项的源代码并解压缩
2629
> NGINX依赖于3个库:PCRE,zlib和OpenSSL:
2730
```bash
@@ -34,9 +37,18 @@
3437
# OpenSSL version 1.0.2 - 1.1.0
3538
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz
3639
```
37-
+ 4、删除所有.tar.gz文件。我们不再需要它们了,`rm -rf *.tar.gz`
38-
+ 5、转到NGINX源目录:`cd ~/nginx-1.13.1`
39-
+ 6、有关帮助,您可以通过运行以下列出可用的配置开关:`./configure --help`
40+
+ 4、删除所有.tar.gz文件。我们不再需要了
41+
```bash
42+
wget https://nginx.org/download/nginx-1.13.1.tar.gz && tar zxvf nginx-1.13.1.tar.gz
43+
```
44+
+ 5、转到NGINX源目录:``
45+
```bash
46+
cd ~/nginx-1.13.1
47+
```
48+
+ 6、有关帮助,您可以通过运行以下列出可用的配置开关
49+
```bash
50+
./configure --help
51+
```
4052
+ 7、配置,编译和安装NGINX:
4153
```bash
4254
./configure --prefix=/usr/share/nginx \
@@ -88,7 +100,8 @@
88100
--with-stream_ssl_module \
89101
--with-stream_ssl_preread_module \
90102
--with-debug \
91-
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
103+
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security
104+
-Wdate-time -D_FORTIFY_SOURCE=2' \
92105
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now'
93106
make
94107
sudo make install
@@ -156,8 +169,14 @@
156169
ps aux | grep nginx
157170
curl -I 127.0.0.1
158171
```
159-
+ 16、重新启动Ubuntu VPS以验证NGINX是否自动启动:`sudo shutdown -r now`
160-
+ 17、创建UFW NGINX应用程序配置文件:`sudo vim /etc/ufw/applications.d/nginx`
172+
+ 16、重新启动Ubuntu VPS以验证NGINX是否自动启动:
173+
```bash
174+
sudo shutdown -r now
175+
```
176+
+ 17、创建UFW NGINX应用程序配置文件:
177+
```bash
178+
sudo vim /etc/ufw/applications.d/nginx
179+
```
161180
+ 18、复制/粘贴以下内容:
162181
```bash
163182
[Nginx HTTP]

0 commit comments

Comments
 (0)