pull/16/head
Zhang Peng 2020-01-10 10:33:37 +08:00
parent cd0d78d4ee
commit 5d9ef3b6aa
13 changed files with 672 additions and 325 deletions

View File

@ -10,7 +10,7 @@ root = true
[*]
end_of_line = lf
indent_size = 2
indent_style = tab
indent_style = space
max_line_length = 120
charset = utf-8
trim_trailing_whitespace = true
@ -19,7 +19,7 @@ insert_final_newline = true
[*.{bat, cmd}]
end_of_line = crlf
[*.{java, groovy, kt, sh}]
[*.{java, gradle, groovy, kt, sh}]
indent_size = 4
[*.md]

2
.gitignore vendored
View File

@ -29,6 +29,7 @@ hs_err_pid*
# maven plugin temp files
.flattened-pom.xml
package-lock.json
# ------------------------------- javascript -------------------------------
@ -47,6 +48,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
bundle*.js
book.pdf
# ------------------------------- intellij -------------------------------

440
LICENSE
View File

@ -1,21 +1,427 @@
MIT License
Attribution-ShareAlike 4.0 International
Copyright (c) 2018 Zhang Peng
=======================================================================
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Using Creative Commons Public Licenses
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More_considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public License ("Public
License"). To the extent this Public License may be interpreted as a
contract, You are granted the Licensed Rights in consideration of Your
acceptance of these terms and conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. BY-SA Compatible License means a license listed at
creativecommons.org/compatiblelicenses, approved by Creative
Commons as essentially the equivalent of this Public License.
d. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
e. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
g. License Elements means the license attributes listed in the name
of a Creative Commons Public License. The License Elements of this
Public License are Attribution and ShareAlike.
h. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
i. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
k. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. Additional offer from the Licensor -- Adapted Material.
Every recipient of Adapted Material from You
automatically receives an offer from the Licensor to
exercise the Licensed Rights in the Adapted Material
under the conditions of the Adapter's License You apply.
c. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
b. ShareAlike.
In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons
license with the same License Elements, this version or
later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the
Adapter's License You apply. You may satisfy this condition
in any reasonable manner based on the medium, means, and
context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms
or conditions on, or apply any Effective Technological
Measures to, Adapted Material that restrict exercise of the
rights granted under the Adapter's License You apply.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material,
including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

View File

@ -4,21 +4,37 @@
>
> [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。
## 简介
<!-- TOC depthFrom:2 depthTo:3 -->
- [一、Nginx 简介](#一nginx-简介)
- [二、Nginx 入门](#二nginx-入门)
- [三、Nginx 实战](#三nginx-实战)
- [Http 反向代理](#http-反向代理)
- [Https 反向代理](#https-反向代理)
- [负载均衡](#负载均衡)
- [网站有多个 webapp 的配置](#网站有多个-webapp-的配置)
- [静态站点](#静态站点)
- [搭建文件服务器](#搭建文件服务器)
- [解决跨域](#解决跨域)
- [资源](#资源)
<!-- /TOC -->
## 一、Nginx 简介
**什么是 Nginx?**
**Nginx (engine x)** 是一款轻量级的 Web 服务器 、反向代理服务器及电子邮件IMAP/POP3代理服务器。
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp"/></div><br>
![img](http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp)
**什么是反向代理?**
反向代理Reverse Proxy方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp"/></div><br>
![img](http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp)
## Nginx 入门
## 二、Nginx 入门
> 详细安装方法请参考:[Nginx 安装](docs/nginx-install.md)
@ -56,7 +72,7 @@ nginx.exe -c conf/nginx.conf
如果是运行在 Linux 下,写一个 shell 脚本,大同小异。
## Nginx 实战
## 三、Nginx 实战
我始终认为,各种开发工具的配置还是结合实战来讲述,会让人更易理解。
@ -237,7 +253,7 @@ http {
nginx 也可以实现简单的负载均衡功能。
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp"/></div><br>
![](http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp)
假设这样一个应用场景:将应用部署在 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对所有请求做负载均衡处理下面例子中使用的是加权轮询策略
@ -298,7 +314,7 @@ http {
Nginx 提供了多种负载均衡策略,让我们来一一了解一下:
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/javaweb/#/theory/load-balance)
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/blog/design/theory/load-balance-theory/)
##### 轮询
@ -592,9 +608,9 @@ server {
到此,就完成了。
## 参考
## 资源
- [Nginx 的中文维基](http://tool.oschina.net/apidocs/apidoc?api=nginx-zh)
- [Nginx 开发从入门到精通](http://tengine.taobao.org/book/index.html)
- https://github.com/trimstray/nginx-admins-handbook
- [nginx-admins-handbook](https://github.com/trimstray/nginx-admins-handbook)
- [nginxconfig.io](https://nginxconfig.io/) - 一款 Nginx 配置生成器

View File

@ -1,8 +1,7 @@
<div align="center"><img width="100px" src="http://dunwu.test.upcdn.net/common/logo/zp.png"/></div>
<div align="center"><img width="100px" src="http://dunwu.test.upcdn.net/common/logo/zp.png" /></div>
# nginx-tutorial
> Nginx 极简教程
> 📚 **nginx-tutorial** 是一个 Nginx 极简教程
[开始阅读](README.md)

View File

@ -1,248 +1,140 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Nginx Tutorial</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
<meta content="Nginx Tutorial" name="description"/>
<meta
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
name="viewport"
/>
<link href="http://dunwu.test.upcdn.net/common/logo/zp_50_50.png" rel="icon" type="image/x-icon"/>
<link href="//unpkg.com/docsify/lib/themes/vue.css" rel="stylesheet" title="vue"/>
<style>
h1 + ul {
display: block !important;
}
<head>
<meta charset="UTF-8" />
<title>nginx-tutorial</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<meta content="nginx-tutorial" name="description" />
<meta
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
name="viewport"
/>
<link href="http://dunwu.test.upcdn.net/common/logo/zp_50_50.png" rel="icon" type="image/x-icon" />
<link href="//unpkg.com/docsify/lib/themes/vue.css" rel="stylesheet" />
<link href="//unpkg.com/gitalk/dist/gitalk.css" rel="stylesheet" />
<canvas
id="c_n9"
width="1920"
height="990"
style="position: fixed; top: 0; left: 0; z-index: -1; opacity: 0.5;"
></canvas>
<style>
/*超链接样式*/
.cover-main a,
.content a,
.sidebar a,
.sidebar ul li a,
.sidebar ul li a strong {
text-decoration: none !important;
}
.content img,
.sidebar img {
border: none;
border-radius: 8px;
box-shadow: 0 0 8px grey;
}
/*超链接悬浮样式*/
.cover-main a:hover,
.content a:hover,
.sidebar a:hover,
.sidebar ul li a:hover,
.sidebar ul li a strong:hover {
color: #0077e6;
text-decoration: underline !important;
}
.content,
.sidebar,
.sidebar-toggle,
body,
.search input {
color: #6B615F !important;
background-color: #FFF4E6 !important;
}
.sidebar-nav ul {
padding-left: 15px;
}
.content strong,
.sidebar strong,
body strong {
color: #5C5869 !important;
}
</style>
<style>
.cover-main .anchor span {
text-align: center;
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: masked-animation 1.5s infinite linear;
font-family: "Brush Script MT", 隶书, serif;
font-weight: 600;
}
/*侧边栏样式*/
.sidebar .sidebar-nav h1 {
background-color: #f8f8f8;
margin: 10px;
padding-left: 10px;
text-align: center;
font-size: 12px;
text-transform: uppercase;
}
.cover-main blockquote p {
color: #5C5869;
font-family: "Arial", 隶书, serif;
}
/*文章标题加动态刷新颜色效果*/
section.cover h1 span,
.markdown-section h1 span {
font-weight: 600;
font-family: zillaslab, Palatino, 'Palatino Linotype', 'Microsoft YaHei', serif;
background-image: -webkit-linear-gradient(left, #9fa5d5, #c4cdd2 50%, #e8f5ca);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: hue 5s infinite linear;
text-shadow: 2px 2px 2px transparent;
}
.cover-main ul a:hover {
color: #FE4165 !important;
}
/*动态效果*/
@-webkit-keyframes hue {
from {
-webkit-filter: hue-rotate(0deg);
-moz-filter: hue-rotate(0deg);
}
to {
-webkit-filter: hue-rotate(-360deg);
-moz-filter: hue-rotate(-360deg);
}
}
</style>
</head>
<body>
<div id="app">正在加载...</div>
.cover-main p a:hover {
text-align: center;
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: masked-animation 1.5s infinite linear;
}
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify-edit-on-github/index.js"></script>
/* content 样式内容 */
.sidebar a,
.content a {
color: #399AB2 !important;
text-decoration: none !important;
}
<script>
window.$docsify = {
name: 'Nginx Tutorial',
repo: 'https://github.com/dunwu/nginx-tutorial',
logo: 'http://dunwu.test.upcdn.net/common/logo/zp_100_100.png',
themeColor: '#6190E8',
auto2top: true,
coverpage: 'coverpage.md',
loadSidebar: 'sidebar.md',
autoHeader: false,
maxLevel: 4,
subMaxLevel: 2,
mergeNavbar: true,
formatUpdated: '{YYYY}/{MM}/{DD} {HH}:{mm}',
search: {
maxAge: 86400000,
paths: ['/'],
placeholder: '🔍 搜索',
noData: '😭 没有结果!',
depth: 4
},
pagination: {
previousText: '上一篇',
nextText: '下一篇',
crossChapter: true
},
plugins: [
EditOnGithubPlugin.create('https://github.com/dunwu/nginx-tutorial/tree/master/docs/', null, function(file) {
if (file.indexOf('en') === -1) {
return '📝 编辑文档'
} else {
return '📝 Edit Document'
}
})
]
}
</script>
.sidebar a:hover,
.content a:hover {
color: #FE4165 !important;
text-decoration: underline !important;
}
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.js"></script>
<script src="//unpkg.com/docsify-pagination/dist/docsify-pagination.min.js"></script>
.content h1 :hover,
.content h2 :hover,
.content h3 :hover,
.content h4 :hover {
text-align: center;
background-image: -webkit-linear-gradient(left, #FFDCB4, #B96972 25%, #E88A57 50%, #804170 75%, #A596CD);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: masked-animation 1.5s infinite linear;
font-family: "微软雅黑", serif;
font-weight: bold;
}
<!--代码高亮-->
<!--@see https://github.com/PrismJS/prism -->
<script src="//unpkg.com/prismjs/components/prism-basic.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-batch.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
@-webkit-keyframes masked-animation {
0% {
background-position: 0 0;
}
100% {
background-position: -100% 0;
}
}
.content h1 a,
.content h1 span {
color: #399AB2 !important;
font-size: 30px;
text-shadow: 2px 2px 5px grey;
}
.content h2 a,
.content h2 span {
color: #60497C !important;
font-size: 26px;
text-shadow: 2px 2px 5px grey;
}
.content h3 a,
.content h3 span {
color: #346093 !important;
font-size: 22px;
text-shadow: 2px 2px 5px grey;
}
.content h4 a,
.content h4 span {
font-size: 18px;
color: #78943A;
text-shadow: 2px 2px 5px grey;
}
img.emoji {
border: none;
border-radius: 0;
box-shadow: none;
}
</style>
<style>
.content > p {
font-size: 16px !important;
line-height: 24px;
}
.content blockquote {
display: block;
padding: 0 16px;
border-left: 8px solid #DDDFE4;
background: #FFF2C9;
overflow: auto;
}
.content pre {
padding-left: 0 !important;
padding-right: 0 !important;
border-radius: 8px;
box-shadow: 1px 1px 20px 3px #DDDDDD !important;
}
.content code {
background-color: white;
border-radius: 6px;
box-shadow: 1px 1px 1px whitesmoke;
}
.content table {
display: table;
padding-left: 0 !important;
padding-right: 0 !important;
box-shadow: 2px 2px 20px 6px #DDDDDD !important;
}
.content th {
font-weight: bold;
font-size: 16px;
background-color: #CCE6B6;
}
</style>
<style>
@media (min-width: 600px) {
.markdown-section pre > code {
font-size: 0.9rem !important;
}
}
@media (max-width: 600px) {
.markdown-section pre > code {
padding-top: 5px;
padding-bottom: 5px;
}
pre:after {
content: "" !important;
}
}
@media (min-width: 600px) {
pre code {
padding-left: 20px !important;
}
}
@media (max-width: 600px) {
pre {
padding-left: 0px !important;
padding-right: 0px !important;
}
}
</style>
</head>
<body>
<div id="app">正在加载...</div>
<script>
window.$docsify = {
name: 'Nginx Tutorial',
repo: 'https://github.com/dunwu/nginx-tutorial',
logo: 'http://dunwu.test.upcdn.net/common/logo/zp_100_100.png',
auto2top: true,
coverpage: 'coverpage.md',
maxLevel: 4,
subMaxLevel: 4,
formatUpdated: '{MM}/{DD} {HH}:{mm}',
search: {
maxAge: 86400000,
paths: ['/'],
placeholder: '🔍 搜索',
noData: '没有结果!',
depth: 4
}
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/emoji.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
<!--代码高亮-->
<!--@see https://github.com/PrismJS/prism -->
<script src="//unpkg.com/prismjs/components/prism-basic.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-batch.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-vim.min.js"></script>
</body>
<!-- <canvas id="c_n9" width="1920" height="990" style="position: fixed; top: 0; left: 0; z-index: -2; opacity: 0.5;"></canvas>-->
<script src="https://files.cnblogs.com/files/jingmoxukong/canvas-nest.min.js" async defer></script>
</body>
</html>

View File

@ -1,16 +1,14 @@
# Nginx 安装
<!-- TOC depthfrom:2 depthto:3 -->
<!-- TOC depthFrom:2 depthTo:3 -->
- [Windows 安装](#windows-安装)
- [Linux 安装](#linux-安装)
- [rpm 包方式(推荐)](#rpm-包方式推荐)
- [源码编译方式](#源码编译方式)
- [安装编译工具及库文件](#安装编译工具及库文件)
- [安装 Nginx](#安装-nginx)
- [Linux 开机自启动](#linux-开机自启动)
- [rpm 包方式](#rpm-包方式)
- [源码编译方式](#源码编译方式)
- [源码编译方式](#源码编译方式-1)
- [脚本](#脚本)
- [参考资料](#参考资料)
@ -20,11 +18,11 @@
1进入[官方下载地址](https://nginx.org/en/download.html)选择合适版本nginx/Windows-xxx
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181023092347.png"/></div><br>
![img](http://dunwu.test.upcdn.net/snap/20180920181023092347.png)
2解压到本地
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181023092044.png"/></div><br>
![img](http://dunwu.test.upcdn.net/snap/20180920181023092044.png)
3启动
@ -144,7 +142,7 @@ $ firewall-cmd --reload
启动后,访问站点:
<br><div align="center"><img src="http://dunwu.test.upcdn.net/snap/20180920181016133223.png"/></div><br>
![img](http://dunwu.test.upcdn.net/snap/20180920181016133223.png)
## Linux 开机自启动
@ -168,7 +166,28 @@ $ systemctl enable nginx.service
## 脚本
| [安装脚本](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft) |
> CentOS7 环境安装脚本:[软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
**安装说明**
- 采用编译方式安装 Nginx, 并将其注册为 systemd 服务
- 安装路径为:`/usr/local/nginx`
- 默认下载安装 `1.16.0` 版本
**使用方法**
- 默认安装 - 执行以下任意命令即可:
```sh
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/nginx-install.sh | bash
wget -qO- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/nginx-install.sh | bash
```
- 自定义安装 - 下载脚本到本地,并按照以下格式执行:
```bash
sh nginx-install.sh [version]
```
## 参考资料

View File

@ -1,57 +1,57 @@
# Nginx 极简教程
> **Nginx 是一个开源的 HTTP 和反向代理服务器,一个邮件代理服务器以及一个通用的 TCP / UDP 代理服务器**
>
> 本项目是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx。
>
> [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。
## 简介
<!-- TOC depthFrom:2 depthTo:3 -->
### 什么是 Nginx?
- [一、Nginx 简介](#一nginx-简介)
- [二、Nginx 入门](#二nginx-入门)
- [三、Nginx 实战](#三nginx-实战)
- [Http 反向代理](#http-反向代理)
- [Https 反向代理](#https-反向代理)
- [负载均衡](#负载均衡)
- [网站有多个 webapp 的配置](#网站有多个-webapp-的配置)
- [静态站点](#静态站点)
- [搭建文件服务器](#搭建文件服务器)
- [解决跨域](#解决跨域)
- [资源](#资源)
Nginx 是一种快速、轻巧且功能强大的 Web 服务器,也可以用作:
<!-- /TOC -->
- 快速 HTTP 反向代理
- 可靠的负载均衡器
- 高性能缓存服务器
- 完善的网络平台
## 一、Nginx 简介
### Nginx 模块化结构
**什么是 Nginx?**
Nginx 有一个主进程和几个工作进程。**主流程的主要目的是读取和评估配置,以及维护工作流程**。**工作进程对请求进行实际处理**。Nginx 使用基于事件的模型和依赖于操作系统的机制来有效地在工作进程之间分配请求
**Nginx (engine x)** 是一款轻量级的 Web 服务器 、反向代理服务器及电子邮件IMAP/POP3代理服务器
Nginx 服务完全遵循模块化设计思想。
![img](http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp)
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp"/></div><br>
### 什么是反向代理?
**什么是反向代理?**
反向代理Reverse Proxy方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp"/></div><br>
![img](http://dunwu.test.upcdn.net/cs/web/nginx/reverse-proxy.png!zp)
## Nginx 命令
## 二、Nginx 入门
> 详细安装方法请参考:[Nginx 安装](nginx-install.md)
> 详细安装方法请参考:[Nginx 安装](docs/nginx-install.md)
nginx 的使用比较简单,就是几条命令。
常用到的命令如下:
- `nginx -h` - 显示帮助
- `nginx -v` - 显示 Nginx 的版本
- `nginx -V` - 显示 Nginx 的版本,编译器版本和配置参数。
- `nginx -t` - 测试 Nginx 配置
- `nginx -c <文件名>` - 设置配置文件(默认:`/etc/nginx/nginx.conf`
- `nginx -p <目录>` - 设置前缀路径(默认值:`/etc/nginx/`
- `nginx -T` - 测试 Nginx 配置并在屏幕上打印经过验证的配置
- `nginx -s <signal>` - 向 Nginx 主进程发送信号:
- `stop` - 快速关闭 Nginx可能不保存相关信息并迅速终止 web 服务
- `quit` - 平稳关闭 Nginx保存相关信息有安排的结束 web 服务
- `reload` - 重新加载配置而不停止进程
- `reopen` - 重新打开日志文件
- `nginx -g <指令>` - 将全局指令设置为超出配置文件
```batch
nginx -s stop 快速关闭Nginx可能不保存相关信息并迅速终止web服务。
nginx -s quit 平稳关闭Nginx保存相关信息有安排的结束web服务。
nginx -s reload 因改变了Nginx相关配置需要重新加载配置而重载。
nginx -s reopen 重新打开日志文件。
nginx -c filename 为 Nginx 指定一个配置文件,来代替缺省的。
nginx -t 不运行仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
nginx -v 显示 nginx 的版本。
nginx -V 显示 nginx 的版本,编译器版本和配置参数。
```
如果不想每次都敲命令,可以在 nginx 安装目录下新添一个启动批处理文件**startup.bat**,双击即可运行。内容如下:
@ -72,7 +72,7 @@ nginx.exe -c conf/nginx.conf
如果是运行在 Linux 下,写一个 shell 脚本,大同小异。
## Nginx 实战
## 三、Nginx 实战
我始终认为,各种开发工具的配置还是结合实战来讲述,会让人更易理解。
@ -196,15 +196,15 @@ http {
好了,让我们来试试吧:
1. 启动 webapp注意启动绑定的端口要和 nginx 中的 `upstream` 设置的端口保持一致。
2. 更改 host在 C:\Windows\System32\drivers\etc 目录下的 host 文件中添加一条 DNS 记录
1. 启动 webapp注意启动绑定的端口要和 nginx 中的 `upstream` 设置的端口保持一致。
2. 更改 host在 C:\Windows\System32\drivers\etc 目录下的 host 文件中添加一条 DNS 记录
```
127.0.0.1 www.helloworld.com
```
3. 启动前文中 startup.bat 的命令
4. 在浏览器中访问 www.helloworld.com不出意外已经可以访问了。
3. 启动前文中 startup.bat 的命令
4. 在浏览器中访问 www.helloworld.com不出意外已经可以访问了。
### Https 反向代理
@ -253,7 +253,7 @@ http {
nginx 也可以实现简单的负载均衡功能。
<br><div align="center"><img src="http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp"/></div><br>
![](http://dunwu.test.upcdn.net/cs/web/nginx/nginx-load-balance.png!zp)
假设这样一个应用场景:将应用部署在 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对所有请求做负载均衡处理下面例子中使用的是加权轮询策略
@ -314,7 +314,7 @@ http {
Nginx 提供了多种负载均衡策略,让我们来一一了解一下:
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/javaweb/#/theory/load-balance)
负载均衡策略在各种分布式系统中基本上原理一致,对于原理有兴趣,不妨参考 [负载均衡](https://dunwu.github.io/blog/design/theory/load-balance-theory/)
##### 轮询
@ -526,11 +526,11 @@ web 领域开发中,经常采用前后端分离模式。这种模式下,前
各自独立的 web app 在互相访问时,势必存在跨域问题。解决跨域问题一般有两种思路:
1. **CORS**
1. **CORS**
在后端服务器设置 HTTP 响应头,把你需要允许访问的域名加入 `Access-Control-Allow-Origin` 中。
2. **jsonp**
2. **jsonp**
把后端根据请求,构造 json 数据,并返回,前端用 jsonp 跨域。
@ -608,9 +608,9 @@ server {
到此,就完成了。
## 参考
## 资源
- [Nginx 的中文维基](http://tool.oschina.net/apidocs/apidoc?api=nginx-zh)
- [Nginx 开发从入门到精通](http://tengine.taobao.org/book/index.html)
- https://github.com/trimstray/nginx-admins-handbook
- [nginx-admins-handbook](https://github.com/trimstray/nginx-admins-handbook)
- [nginxconfig.io](https://nginxconfig.io/) - 一款 Nginx 配置生成器

6
docs/sidebar.md 100644
View File

@ -0,0 +1,6 @@
# nginx-tutorial
- [Nginx 快速教程](nginx-quickstart.md)
- [Nginx 安装](nginx-install.md)
- [Nginx 配置](nginx-configuration.md)
- [Nginx 问题](nginx-faq.md)

View File

@ -91,7 +91,7 @@ nginx-1.14.0 是 Nginx 的 windows 环境的 1.14.0 官方版本。之所以把
2. 配置 hosts`127.0.0.1 www.demo01.com`
3. 在浏览器中访问www.demo01.com
<br><div align="center"><img src="images\nginx-demo01.png"/></div><br>
![img](images\nginx-demo01.png)
### Demo02 - 负载均衡示例
@ -111,7 +111,7 @@ nginx-1.14.0 是 Nginx 的 windows 环境的 1.14.0 官方版本。之所以把
如图所示:三次访问的端口号各不相同,说明三个服务器各自均有不同机率(基于权重)被访问。
<br><div align="center"><img src="images\nginx-demo02.png"/></div><br>
![img](images\nginx-demo02.png)
### Demo03 - 多 webapp 示例
@ -137,7 +137,7 @@ Nginx 配置文件:[demo03.conf](nginx-1.14.0/conf/conf.d/demo03.conf)
如图所示:三次访问的 context 和端口号各不相同。说明 Nginx 根据不同的 context 将请求分发到指定的服务器上。
<br><div align="center"><img src="images\nginx-demo03.png"/></div><br>
![img](images\nginx-demo03.png)
### Demo04 - 前后端分离示例
@ -169,11 +169,11 @@ Nginx 配置文件:[demo04.conf](nginx-1.14.0/conf/conf.d/demo04.conf)
效果图:
<br><div align="center"><img src="images\nginx-demo04.png"/></div><br>
![img](images\nginx-demo04.png)
按 F12 打开浏览器控制台,输入用户名/密码admin/123456执行登录操作。如下图所示可以看到登录后的访问请求被转发到了 Nginx 配置的服务器地址。
<br><div align="center"><img src="<images\nginx-demo04(2"/></div><br>
![img](<images\nginx-demo04(2)
### Demo05 - 配置文件服务器示例
@ -199,7 +199,7 @@ Nginx 配置文件:[demo05.conf](nginx-1.14.0/conf/conf.d/demo05.conf)
效果图如下:
<br><div align="center"><img src="images\nginx-demo05.png"/></div><br>
![img](images\nginx-demo05.png)
### Demo06 - 静态站点示例
@ -220,4 +220,4 @@ Nginx 中的配置要点:
效果图如下:
<br><div align="center"><img src="images\nginx-demo06.png"/></div><br>
![img](images\nginx-demo06.png)

View File

@ -14,7 +14,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<spring.version>5.0.2.RELEASE</spring.version>
<tomcat.version>8.5.40</tomcat.version>
<tomcat.version>8.5.50</tomcat.version>
</properties>
<dependencies>
<!-- javaee begin -->

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
ln -s /app/ck-puck-front/node_modules/ node_modules
nvm use 8.1.0

View File

@ -0,0 +1,7 @@
/**
* @see https://prettier.io/docs/en/options.html
* @see https://prettier.io/docs/en/configuration.html
*/
module.exports = {
tabWidth: 2, semi: false, singleQuote: true
}