Skip to content

Commit 5d9ef3b

Browse files
committedJan 10, 2020
update
1 parent cd0d78d commit 5d9ef3b

13 files changed

+686
-339
lines changed
 

‎.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ root = true
1010
[*]
1111
end_of_line = lf
1212
indent_size = 2
13-
indent_style = tab
13+
indent_style = space
1414
max_line_length = 120
1515
charset = utf-8
1616
trim_trailing_whitespace = true
@@ -19,7 +19,7 @@ insert_final_newline = true
1919
[*.{bat, cmd}]
2020
end_of_line = crlf
2121

22-
[*.{java, groovy, kt, sh}]
22+
[*.{java, gradle, groovy, kt, sh}]
2323
indent_size = 4
2424

2525
[*.md]

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ hs_err_pid*
2929

3030
# maven plugin temp files
3131
.flattened-pom.xml
32+
package-lock.json
3233

3334

3435
# ------------------------------- javascript -------------------------------
@@ -47,6 +48,7 @@ npm-debug.log*
4748
yarn-debug.log*
4849
yarn-error.log*
4950
bundle*.js
51+
book.pdf
5052

5153

5254
# ------------------------------- intellij -------------------------------

‎LICENSE

Lines changed: 427 additions & 21 deletions
Large diffs are not rendered by default.

‎README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,37 @@
44
>
55
> [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。
66
7-
## 简介
7+
<!-- TOC depthFrom:2 depthTo:3 -->
8+
9+
- [一、Nginx 简介](#一nginx-简介)
10+
- [二、Nginx 入门](#二nginx-入门)
11+
- [三、Nginx 实战](#三nginx-实战)
12+
- [Http 反向代理](#http-反向代理)
13+
- [Https 反向代理](#https-反向代理)
14+
- [负载均衡](#负载均衡)
15+
- [网站有多个 webapp 的配置](#网站有多个-webapp-的配置)
16+
- [静态站点](#静态站点)
17+
- [搭建文件服务器](#搭建文件服务器)
18+
- [解决跨域](#解决跨域)
19+
- [资源](#资源)
20+
21+
<!-- /TOC -->
22+
23+
## 一、Nginx 简介
824

925
**什么是 Nginx?**
1026

1127
**Nginx (engine x)** 是一款轻量级的 Web 服务器 、反向代理服务器及电子邮件(IMAP/POP3)代理服务器。
1228

13-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp"/></div><br>
29+
![img](http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp)
1430

1531
**什么是反向代理?**
1632

1733
反向代理(Reverse Proxy)方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
1834

19-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp"/></div><br>
35+
![img](http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp)
2036

21-
## Nginx 入门
37+
## 二、Nginx 入门
2238

2339
> 详细安装方法请参考:[Nginx 安装](docs/nginx-install.md)
2440
@@ -56,7 +72,7 @@ nginx.exe -c conf/nginx.conf
5672

5773
如果是运行在 Linux 下,写一个 shell 脚本,大同小异。
5874

59-
## Nginx 实战
75+
## 三、Nginx 实战
6076

6177
我始终认为,各种开发工具的配置还是结合实战来讲述,会让人更易理解。
6278

@@ -237,7 +253,7 @@ http {
237253

238254
nginx 也可以实现简单的负载均衡功能。
239255

240-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp"/></div><br>
256+
![](http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp)
241257

242258
假设这样一个应用场景:将应用部署在 192.168.1.11:80、192.168.1.12:80、192.168.1.13:80 三台 linux 环境的服务器上。网站域名叫 www.helloworld.com,公网 IP 为 192.168.1.11。在公网 IP 所在的服务器上部署 nginx,对所有请求做负载均衡处理(下面例子中使用的是加权轮询策略)。
243259

@@ -298,7 +314,7 @@ http {
298314

299315
Nginx 提供了多种负载均衡策略,让我们来一一了解一下:
300316

301-
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/javaweb/#/theory/load-balance)
317+
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/blog/design/theory/load-balance-theory/)
302318

303319
##### 轮询
304320

@@ -592,9 +608,9 @@ server {
592608

593609
到此,就完成了。
594610

595-
## 参考
611+
## 资源
596612

597613
- [Nginx 的中文维基](http://tool.oschina.net/apidocs/apidoc?api=nginx-zh)
598614
- [Nginx 开发从入门到精通](http://tengine.taobao.org/book/index.html)
599-
- https://github.com/trimstray/nginx-admins-handbook
615+
- [nginx-admins-handbook](https://github.com/trimstray/nginx-admins-handbook)
600616
- [nginxconfig.io](https://nginxconfig.io/) - 一款 Nginx 配置生成器

‎docs/coverpage.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<div align="center"><img width="100px" src="http://dunwu.test.upcdn.net/common/logo/zp.png"/></div>
1+
<div align="center"><img width="100px" src="http://dunwu.test.upcdn.net/common/logo/zp.png" /></div>
22

33
# nginx-tutorial
44

5-
> Nginx 极简教程
5+
> 📚 **nginx-tutorial** 是一个 Nginx 极简教程
66
77
[开始阅读](README.md)
8-

‎docs/index.html

Lines changed: 137 additions & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -1,248 +1,140 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8"/>
5-
<title>Nginx Tutorial</title>
6-
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
7-
<meta content="Nginx Tutorial" name="description"/>
8-
<meta
9-
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
10-
name="viewport"
11-
/>
12-
<link href="http://dunwu.test.upcdn.net/common/logo/zp_50_50.png" rel="icon" type="image/x-icon"/>
13-
<link href="//unpkg.com/docsify/lib/themes/vue.css" rel="stylesheet" title="vue"/>
14-
<style>
15-
h1 + ul {
16-
display: block !important;
17-
}
18-
19-
.content img,
20-
.sidebar img {
21-
border: none;
22-
border-radius: 8px;
23-
box-shadow: 0 0 8px grey;
24-
}
25-
26-
.content,
27-
.sidebar,
28-
.sidebar-toggle,
29-
body,
30-
.search input {
31-
color: #6B615F !important;
32-
background-color: #FFF4E6 !important;
33-
}
34-
35-
.content strong,
36-
.sidebar strong,
37-
body strong {
38-
color: #5C5869 !important;
39-
}
40-
</style>
41-
<style>
42-
.cover-main .anchor span {
43-
text-align: center;
44-
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
45-
-webkit-text-fill-color: transparent;
46-
-webkit-background-clip: text;
47-
-webkit-background-size: 200% 100%;
48-
-webkit-animation: masked-animation 1.5s infinite linear;
49-
font-family: "Brush Script MT", 隶书, serif;
50-
font-weight: 600;
51-
}
52-
53-
.cover-main blockquote p {
54-
color: #5C5869;
55-
font-family: "Arial", 隶书, serif;
56-
}
57-
58-
.cover-main ul a:hover {
59-
color: #FE4165 !important;
60-
}
61-
62-
.cover-main p a:hover {
63-
text-align: center;
64-
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
65-
-webkit-text-fill-color: transparent;
66-
-webkit-background-clip: text;
67-
-webkit-background-size: 200% 100%;
68-
-webkit-animation: masked-animation 1.5s infinite linear;
69-
}
70-
71-
/* content 样式内容 */
72-
.sidebar a,
73-
.content a {
74-
color: #399AB2 !important;
75-
text-decoration: none !important;
76-
}
77-
78-
.sidebar a:hover,
79-
.content a:hover {
80-
color: #FE4165 !important;
81-
text-decoration: underline !important;
82-
}
83-
84-
.content h1 :hover,
85-
.content h2 :hover,
86-
.content h3 :hover,
87-
.content h4 :hover {
88-
text-align: center;
89-
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
90-
-webkit-text-fill-color: transparent;
91-
-webkit-background-clip: text;
92-
-webkit-background-size: 200% 100%;
93-
-webkit-animation: masked-animation 1.5s infinite linear;
94-
font-family: "微软雅黑", serif;
95-
font-weight: bold;
96-
}
97-
98-
@-webkit-keyframes masked-animation {
99-
0% {
100-
background-position: 0 0;
101-
}
102-
100% {
103-
background-position: -100% 0;
104-
}
105-
}
106-
107-
.content h1 a,
108-
.content h1 span {
109-
color: #399AB2 !important;
110-
font-size: 30px;
111-
text-shadow: 2px 2px 5px grey;
112-
}
113-
114-
.content h2 a,
115-
.content h2 span {
116-
color: #60497C !important;
117-
font-size: 26px;
118-
text-shadow: 2px 2px 5px grey;
119-
}
120-
121-
.content h3 a,
122-
.content h3 span {
123-
color: #346093 !important;
124-
font-size: 22px;
125-
text-shadow: 2px 2px 5px grey;
126-
}
127-
128-
.content h4 a,
129-
.content h4 span {
130-
font-size: 18px;
131-
color: #78943A;
132-
text-shadow: 2px 2px 5px grey;
133-
}
134-
135-
img.emoji {
136-
border: none;
137-
border-radius: 0;
138-
box-shadow: none;
139-
}
140-
</style>
141-
<style>
142-
.content > p {
143-
font-size: 16px !important;
144-
line-height: 24px;
145-
}
146-
147-
.content blockquote {
148-
display: block;
149-
padding: 0 16px;
150-
border-left: 8px solid #DDDFE4;
151-
background: #FFF2C9;
152-
overflow: auto;
153-
}
154-
155-
.content pre {
156-
padding-left: 0 !important;
157-
padding-right: 0 !important;
158-
border-radius: 8px;
159-
box-shadow: 1px 1px 20px 3px #DDDDDD !important;
160-
}
161-
162-
.content code {
163-
background-color: white;
164-
border-radius: 6px;
165-
box-shadow: 1px 1px 1px whitesmoke;
166-
}
167-
168-
.content table {
169-
display: table;
170-
padding-left: 0 !important;
171-
padding-right: 0 !important;
172-
box-shadow: 2px 2px 20px 6px #DDDDDD !important;
173-
}
174-
175-
.content th {
176-
font-weight: bold;
177-
font-size: 16px;
178-
background-color: #CCE6B6;
179-
}
180-
</style>
181-
<style>
182-
@media (min-width: 600px) {
183-
.markdown-section pre > code {
184-
font-size: 0.9rem !important;
185-
}
186-
}
187-
188-
@media (max-width: 600px) {
189-
.markdown-section pre > code {
190-
padding-top: 5px;
191-
padding-bottom: 5px;
192-
}
193-
194-
pre:after {
195-
content: "" !important;
196-
}
197-
}
198-
199-
@media (min-width: 600px) {
200-
pre code {
201-
padding-left: 20px !important;
202-
}
203-
}
204-
205-
@media (max-width: 600px) {
206-
pre {
207-
padding-left: 0px !important;
208-
padding-right: 0px !important;
209-
}
210-
}
211-
</style>
212-
</head>
213-
<body>
214-
<div id="app">正在加载...</div>
215-
<script>
216-
window.$docsify = {
217-
name: 'Nginx Tutorial',
218-
repo: 'https://github.com/dunwu/nginx-tutorial',
219-
logo: 'http://dunwu.test.upcdn.net/common/logo/zp_100_100.png',
220-
auto2top: true,
221-
coverpage: 'coverpage.md',
222-
maxLevel: 4,
223-
subMaxLevel: 4,
224-
formatUpdated: '{MM}/{DD} {HH}:{mm}',
225-
search: {
226-
maxAge: 86400000,
227-
paths: ['/'],
228-
placeholder: '🔍 搜索',
229-
noData: '没有结果!',
230-
depth: 4
231-
}
232-
}
233-
</script>
234-
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
235-
<script src="//unpkg.com/docsify/lib/plugins/emoji.js"></script>
236-
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.js"></script>
237-
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
238-
239-
<!--代码高亮-->
240-
<!--@see https://github.com/PrismJS/prism -->
241-
<script src="//unpkg.com/prismjs/components/prism-basic.min.js"></script>
242-
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
243-
<script src="//unpkg.com/prismjs/components/prism-batch.min.js"></script>
244-
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
245-
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
246-
<script src="//unpkg.com/prismjs/components/prism-vim.min.js"></script>
247-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>nginx-tutorial</title>
6+
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
7+
<meta content="nginx-tutorial" name="description" />
8+
<meta
9+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
10+
name="viewport"
11+
/>
12+
<link href="http://dunwu.test.upcdn.net/common/logo/zp_50_50.png" rel="icon" type="image/x-icon" />
13+
<link href="//unpkg.com/docsify/lib/themes/vue.css" rel="stylesheet" />
14+
<link href="//unpkg.com/gitalk/dist/gitalk.css" rel="stylesheet" />
15+
<canvas
16+
id="c_n9"
17+
width="1920"
18+
height="990"
19+
style="position: fixed; top: 0; left: 0; z-index: -1; opacity: 0.5;"
20+
></canvas>
21+
<style>
22+
/*超链接样式*/
23+
.cover-main a,
24+
.content a,
25+
.sidebar a,
26+
.sidebar ul li a,
27+
.sidebar ul li a strong {
28+
text-decoration: none !important;
29+
}
30+
31+
/*超链接悬浮样式*/
32+
.cover-main a:hover,
33+
.content a:hover,
34+
.sidebar a:hover,
35+
.sidebar ul li a:hover,
36+
.sidebar ul li a strong:hover {
37+
color: #0077e6;
38+
text-decoration: underline !important;
39+
}
40+
41+
.sidebar-nav ul {
42+
padding-left: 15px;
43+
}
44+
45+
/*侧边栏样式*/
46+
.sidebar .sidebar-nav h1 {
47+
background-color: #f8f8f8;
48+
margin: 10px;
49+
padding-left: 10px;
50+
text-align: center;
51+
font-size: 12px;
52+
text-transform: uppercase;
53+
}
54+
55+
/*文章标题加动态刷新颜色效果*/
56+
section.cover h1 span,
57+
.markdown-section h1 span {
58+
font-weight: 600;
59+
font-family: zillaslab, Palatino, 'Palatino Linotype', 'Microsoft YaHei', serif;
60+
background-image: -webkit-linear-gradient(left, #9fa5d5, #c4cdd2 50%, #e8f5ca);
61+
-webkit-text-fill-color: transparent;
62+
-webkit-background-clip: text;
63+
-webkit-background-size: 200% 100%;
64+
-webkit-animation: hue 5s infinite linear;
65+
text-shadow: 2px 2px 2px transparent;
66+
}
67+
68+
/*动态效果*/
69+
@-webkit-keyframes hue {
70+
from {
71+
-webkit-filter: hue-rotate(0deg);
72+
-moz-filter: hue-rotate(0deg);
73+
}
74+
to {
75+
-webkit-filter: hue-rotate(-360deg);
76+
-moz-filter: hue-rotate(-360deg);
77+
}
78+
}
79+
</style>
80+
</head>
81+
<body>
82+
<div id="app">正在加载...</div>
83+
84+
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
85+
<script src="//unpkg.com/docsify-edit-on-github/index.js"></script>
86+
87+
<script>
88+
window.$docsify = {
89+
name: 'Nginx Tutorial',
90+
repo: 'https://github.com/dunwu/nginx-tutorial',
91+
logo: 'http://dunwu.test.upcdn.net/common/logo/zp_100_100.png',
92+
themeColor: '#6190E8',
93+
auto2top: true,
94+
coverpage: 'coverpage.md',
95+
loadSidebar: 'sidebar.md',
96+
autoHeader: false,
97+
maxLevel: 4,
98+
subMaxLevel: 2,
99+
mergeNavbar: true,
100+
formatUpdated: '{YYYY}/{MM}/{DD} {HH}:{mm}',
101+
search: {
102+
maxAge: 86400000,
103+
paths: ['/'],
104+
placeholder: '🔍 搜索',
105+
noData: '😭 没有结果!',
106+
depth: 4
107+
},
108+
pagination: {
109+
previousText: '上一篇',
110+
nextText: '下一篇',
111+
crossChapter: true
112+
},
113+
plugins: [
114+
EditOnGithubPlugin.create('https://github.com/dunwu/nginx-tutorial/tree/master/docs/', null, function(file) {
115+
if (file.indexOf('en') === -1) {
116+
return '📝 编辑文档'
117+
} else {
118+
return '📝 Edit Document'
119+
}
120+
})
121+
]
122+
}
123+
</script>
124+
125+
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
126+
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.js"></script>
127+
<script src="//unpkg.com/docsify-pagination/dist/docsify-pagination.min.js"></script>
128+
129+
<!--代码高亮-->
130+
<!--@see https://github.com/PrismJS/prism -->
131+
<script src="//unpkg.com/prismjs/components/prism-basic.min.js"></script>
132+
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
133+
<script src="//unpkg.com/prismjs/components/prism-batch.min.js"></script>
134+
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
135+
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
136+
137+
<!-- <canvas id="c_n9" width="1920" height="990" style="position: fixed; top: 0; left: 0; z-index: -2; opacity: 0.5;"></canvas>-->
138+
<script src="https://files.cnblogs.com/files/jingmoxukong/canvas-nest.min.js" async defer></script>
139+
</body>
248140
</html>

‎docs/nginx-install.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Nginx 安装
22

3-
<!-- TOC depthfrom:2 depthto:3 -->
3+
<!-- TOC depthFrom:2 depthTo:3 -->
44

55
- [Windows 安装](#windows-安装)
66
- [Linux 安装](#linux-安装)
77
- [rpm 包方式(推荐)](#rpm-包方式推荐)
88
- [源码编译方式](#源码编译方式)
9-
- [安装编译工具及库文件](#安装编译工具及库文件)
10-
- [安装 Nginx](#安装-nginx)
119
- [Linux 开机自启动](#linux-开机自启动)
1210
- [rpm 包方式](#rpm-包方式)
13-
- [源码编译方式](#源码编译方式)
11+
- [源码编译方式](#源码编译方式-1)
1412
- [脚本](#脚本)
1513
- [参考资料](#参考资料)
1614

@@ -20,11 +18,11 @@
2018

2119
(1)进入[官方下载地址](https://nginx.org/en/download.html),选择合适版本(nginx/Windows-xxx)。
2220

23-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181023092347.png"/></div><br>
21+
![img](http://dunwu.test.upcdn.net/snap/20180920181023092347.png)
2422

2523
(2)解压到本地
2624

27-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181023092044.png"/></div><br>
25+
![img](http://dunwu.test.upcdn.net/snap/20180920181023092044.png)
2826

2927
(3)启动
3028

@@ -144,7 +142,7 @@ $ firewall-cmd --reload
144142

145143
启动后,访问站点:
146144

147-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181016133223.png"/></div><br>
145+
![img](http://dunwu.test.upcdn.net/snap/20180920181016133223.png)
148146

149147
## Linux 开机自启动
150148

@@ -168,7 +166,28 @@ $ systemctl enable nginx.service
168166

169167
## 脚本
170168

171-
| [安装脚本](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft) |
169+
> CentOS7 环境安装脚本:[软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
170+
171+
**安装说明**
172+
173+
- 采用编译方式安装 Nginx, 并将其注册为 systemd 服务
174+
- 安装路径为:`/usr/local/nginx`
175+
- 默认下载安装 `1.16.0` 版本
176+
177+
**使用方法**
178+
179+
- 默认安装 - 执行以下任意命令即可:
180+
181+
```sh
182+
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/nginx-install.sh | bash
183+
wget -qO- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/nginx-install.sh | bash
184+
```
185+
186+
- 自定义安装 - 下载脚本到本地,并按照以下格式执行:
187+
188+
```bash
189+
sh nginx-install.sh [version]
190+
```
172191

173192
## 参考资料
174193

‎docs/nginx-quickstart.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
# Nginx 极简教程
22

3-
> **Nginx 是一个开源的 HTTP 和反向代理服务器,一个邮件代理服务器以及一个通用的 TCP / UDP 代理服务器**
4-
>
53
> 本项目是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx。
64
>
75
> [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。
86
9-
## 简介
10-
11-
### 什么是 Nginx?
7+
<!-- TOC depthFrom:2 depthTo:3 -->
128

13-
Nginx 是一种快速、轻巧且功能强大的 Web 服务器,也可以用作:
9+
- [一、Nginx 简介](#一nginx-简介)
10+
- [二、Nginx 入门](#二nginx-入门)
11+
- [三、Nginx 实战](#三nginx-实战)
12+
- [Http 反向代理](#http-反向代理)
13+
- [Https 反向代理](#https-反向代理)
14+
- [负载均衡](#负载均衡)
15+
- [网站有多个 webapp 的配置](#网站有多个-webapp-的配置)
16+
- [静态站点](#静态站点)
17+
- [搭建文件服务器](#搭建文件服务器)
18+
- [解决跨域](#解决跨域)
19+
- [资源](#资源)
1420

15-
- 快速 HTTP 反向代理
16-
- 可靠的负载均衡器
17-
- 高性能缓存服务器
18-
- 完善的网络平台
21+
<!-- /TOC -->
1922

20-
### Nginx 模块化结构
23+
## 一、Nginx 简介
2124

22-
Nginx 有一个主进程和几个工作进程。**主流程的主要目的是读取和评估配置,以及维护工作流程****工作进程对请求进行实际处理**。Nginx 使用基于事件的模型和依赖于操作系统的机制来有效地在工作进程之间分配请求。
25+
**什么是 Nginx?**
2326

24-
Nginx 服务完全遵循模块化设计思想
27+
**Nginx (engine x)** 是一款轻量级的 Web 服务器 、反向代理服务器及电子邮件(IMAP/POP3)代理服务器
2528

26-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp"/></div><br>
29+
![img](http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp)
2730

28-
### 什么是反向代理?
31+
**什么是反向代理?**
2932

3033
反向代理(Reverse Proxy)方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
3134

32-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp"/></div><br>
35+
![img](http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp)
3336

34-
## Nginx 命令
37+
## 二、Nginx 入门
3538

36-
> 详细安装方法请参考:[Nginx 安装](nginx-install.md)
39+
> 详细安装方法请参考:[Nginx 安装](docs/nginx-install.md)
3740
3841
nginx 的使用比较简单,就是几条命令。
3942

4043
常用到的命令如下:
4144

42-
- `nginx -h` - 显示帮助
43-
- `nginx -v` - 显示 Nginx 的版本
44-
- `nginx -V` - 显示 Nginx 的版本,编译器版本和配置参数。
45-
- `nginx -t` - 测试 Nginx 配置
46-
- `nginx -c <文件名>` - 设置配置文件(默认:`/etc/nginx/nginx.conf`
47-
- `nginx -p <目录>` - 设置前缀路径(默认值:`/etc/nginx/`
48-
- `nginx -T` - 测试 Nginx 配置并在屏幕上打印经过验证的配置
49-
- `nginx -s <signal>` - 向 Nginx 主进程发送信号:
50-
- `stop` - 快速关闭 Nginx,可能不保存相关信息,并迅速终止 web 服务
51-
- `quit` - 平稳关闭 Nginx,保存相关信息,有安排的结束 web 服务
52-
- `reload` - 重新加载配置而不停止进程
53-
- `reopen` - 重新打开日志文件
54-
- `nginx -g <指令>` - 将全局指令设置为超出配置文件
45+
```batch
46+
nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
47+
nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。
48+
nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。
49+
nginx -s reopen 重新打开日志文件。
50+
nginx -c filename 为 Nginx 指定一个配置文件,来代替缺省的。
51+
nginx -t 不运行,仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
52+
nginx -v 显示 nginx 的版本。
53+
nginx -V 显示 nginx 的版本,编译器版本和配置参数。
54+
```
5555

5656
如果不想每次都敲命令,可以在 nginx 安装目录下新添一个启动批处理文件**startup.bat**,双击即可运行。内容如下:
5757

@@ -72,7 +72,7 @@ nginx.exe -c conf/nginx.conf
7272

7373
如果是运行在 Linux 下,写一个 shell 脚本,大同小异。
7474

75-
## Nginx 实战
75+
## 三、Nginx 实战
7676

7777
我始终认为,各种开发工具的配置还是结合实战来讲述,会让人更易理解。
7878

@@ -196,15 +196,15 @@ http {
196196

197197
好了,让我们来试试吧:
198198

199-
1. 启动 webapp,注意启动绑定的端口要和 nginx 中的 `upstream` 设置的端口保持一致。
200-
2. 更改 host:在 C:\Windows\System32\drivers\etc 目录下的 host 文件中添加一条 DNS 记录
199+
1. 启动 webapp,注意启动绑定的端口要和 nginx 中的 `upstream` 设置的端口保持一致。
200+
2. 更改 host:在 C:\Windows\System32\drivers\etc 目录下的 host 文件中添加一条 DNS 记录
201201

202202
```
203203
127.0.0.1 www.helloworld.com
204204
```
205205

206-
3. 启动前文中 startup.bat 的命令
207-
4. 在浏览器中访问 www.helloworld.com,不出意外,已经可以访问了。
206+
3. 启动前文中 startup.bat 的命令
207+
4. 在浏览器中访问 www.helloworld.com,不出意外,已经可以访问了。
208208

209209
### Https 反向代理
210210

@@ -253,7 +253,7 @@ http {
253253

254254
nginx 也可以实现简单的负载均衡功能。
255255

256-
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp"/></div><br>
256+
![](http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp)
257257

258258
假设这样一个应用场景:将应用部署在 192.168.1.11:80、192.168.1.12:80、192.168.1.13:80 三台 linux 环境的服务器上。网站域名叫 www.helloworld.com,公网 IP 为 192.168.1.11。在公网 IP 所在的服务器上部署 nginx,对所有请求做负载均衡处理(下面例子中使用的是加权轮询策略)。
259259

@@ -314,7 +314,7 @@ http {
314314

315315
Nginx 提供了多种负载均衡策略,让我们来一一了解一下:
316316

317-
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/javaweb/#/theory/load-balance)
317+
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/blog/design/theory/load-balance-theory/)
318318

319319
##### 轮询
320320

@@ -526,11 +526,11 @@ web 领域开发中,经常采用前后端分离模式。这种模式下,前
526526

527527
各自独立的 web app 在互相访问时,势必存在跨域问题。解决跨域问题一般有两种思路:
528528

529-
1. **CORS**
529+
1. **CORS**
530530

531531
在后端服务器设置 HTTP 响应头,把你需要允许访问的域名加入 `Access-Control-Allow-Origin` 中。
532532

533-
2. **jsonp**
533+
2. **jsonp**
534534

535535
把后端根据请求,构造 json 数据,并返回,前端用 jsonp 跨域。
536536

@@ -608,9 +608,9 @@ server {
608608

609609
到此,就完成了。
610610

611-
## 参考
611+
## 资源
612612

613613
- [Nginx 的中文维基](http://tool.oschina.net/apidocs/apidoc?api=nginx-zh)
614614
- [Nginx 开发从入门到精通](http://tengine.taobao.org/book/index.html)
615-
- https://github.com/trimstray/nginx-admins-handbook
615+
- [nginx-admins-handbook](https://github.com/trimstray/nginx-admins-handbook)
616616
- [nginxconfig.io](https://nginxconfig.io/) - 一款 Nginx 配置生成器

‎docs/sidebar.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# nginx-tutorial
2+
3+
- [Nginx 快速教程](nginx-quickstart.md)
4+
- [Nginx 安装](nginx-install.md)
5+
- [Nginx 配置](nginx-configuration.md)
6+
- [Nginx 问题](nginx-faq.md)

‎examples/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ nginx-1.14.0 是 Nginx 的 windows 环境的 1.14.0 官方版本。之所以把
9191
2. 配置 hosts:`127.0.0.1 www.demo01.com`
9292
3. 在浏览器中访问:www.demo01.com
9393

94-
<br><div align="center"><img src="images\nginx-demo01.png"/></div><br>
94+
![img](images\nginx-demo01.png)
9595

9696
### Demo02 - 负载均衡示例
9797

@@ -111,7 +111,7 @@ nginx-1.14.0 是 Nginx 的 windows 环境的 1.14.0 官方版本。之所以把
111111

112112
如图所示:三次访问的端口号各不相同,说明三个服务器各自均有不同机率(基于权重)被访问。
113113

114-
<br><div align="center"><img src="images\nginx-demo02.png"/></div><br>
114+
![img](images\nginx-demo02.png)
115115

116116
### Demo03 - 多 webapp 示例
117117

@@ -137,7 +137,7 @@ Nginx 配置文件:[demo03.conf](nginx-1.14.0/conf/conf.d/demo03.conf)
137137

138138
如图所示:三次访问的 context 和端口号各不相同。说明 Nginx 根据不同的 context 将请求分发到指定的服务器上。
139139

140-
<br><div align="center"><img src="images\nginx-demo03.png"/></div><br>
140+
![img](images\nginx-demo03.png)
141141

142142
### Demo04 - 前后端分离示例
143143

@@ -169,11 +169,11 @@ Nginx 配置文件:[demo04.conf](nginx-1.14.0/conf/conf.d/demo04.conf)
169169

170170
效果图:
171171

172-
<br><div align="center"><img src="images\nginx-demo04.png"/></div><br>
172+
![img](images\nginx-demo04.png)
173173

174174
按 F12 打开浏览器控制台,输入用户名/密码(admin/123456)执行登录操作。如下图所示,可以看到登录后的访问请求被转发到了 Nginx 配置的服务器地址。
175175

176-
<br><div align="center"><img src="<images\nginx-demo04(2"/></div><br>
176+
![img](<images\nginx-demo04(2)
177177

178178
### Demo05 - 配置文件服务器示例
179179

@@ -199,7 +199,7 @@ Nginx 配置文件:[demo05.conf](nginx-1.14.0/conf/conf.d/demo05.conf)
199199

200200
效果图如下:
201201

202-
<br><div align="center"><img src="images\nginx-demo05.png"/></div><br>
202+
![img](images\nginx-demo05.png)
203203

204204
### Demo06 - 静态站点示例
205205

@@ -220,4 +220,4 @@ Nginx 中的配置要点:
220220

221221
效果图如下:
222222

223-
<br><div align="center"><img src="images\nginx-demo06.png"/></div><br>
223+
![img](images\nginx-demo06.png)

‎examples/javaapp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<maven.compiler.source>${java.version}</maven.compiler.source>
1515
<maven.compiler.target>${java.version}</maven.compiler.target>
1616
<spring.version>5.0.2.RELEASE</spring.version>
17-
<tomcat.version>8.5.40</tomcat.version>
17+
<tomcat.version>8.5.50</tomcat.version>
1818
</properties>
1919
<dependencies>
2020
<!-- javaee begin -->

‎examples/reactapp/scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
ln -s /app/ck-puck-front/node_modules/ node_modules
44
nvm use 8.1.0

‎prettier.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @see https://prettier.io/docs/en/options.html
3+
* @see https://prettier.io/docs/en/configuration.html
4+
*/
5+
module.exports = {
6+
tabWidth: 2, semi: false, singleQuote: true
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.