From 5d9ef3b6aac00f020636ceb3599aafa7aeeb0de2 Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Fri, 10 Jan 2020 10:33:37 +0800 Subject: [PATCH] update --- .editorconfig | 4 +- .gitignore | 2 + LICENSE | 440 +++++++++++++++++++++++++++-- README.md | 34 ++- docs/coverpage.md | 5 +- docs/index.html | 362 +++++++++--------------- docs/nginx-install.md | 35 ++- docs/nginx-quickstart.md | 84 +++--- docs/sidebar.md | 6 + examples/README.md | 14 +- examples/javaapp/pom.xml | 2 +- examples/reactapp/scripts/build.sh | 2 +- prettier.config.js | 7 + 13 files changed, 672 insertions(+), 325 deletions(-) create mode 100644 docs/sidebar.md create mode 100644 prettier.config.js diff --git a/.editorconfig b/.editorconfig index c7ca29b..d72a75e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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] diff --git a/.gitignore b/.gitignore index b887576..4a99239 100644 --- a/.gitignore +++ b/.gitignore @@ -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 ------------------------------- diff --git a/LICENSE b/LICENSE index 6a8657f..3b7b82d 100644 --- a/LICENSE +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index 96a4ea9..0266c8e 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,37 @@ > > [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。 -## 简介 + + +- [一、Nginx 简介](#一nginx-简介) +- [二、Nginx 入门](#二nginx-入门) +- [三、Nginx 实战](#三nginx-实战) + - [Http 反向代理](#http-反向代理) + - [Https 反向代理](#https-反向代理) + - [负载均衡](#负载均衡) + - [网站有多个 webapp 的配置](#网站有多个-webapp-的配置) + - [静态站点](#静态站点) + - [搭建文件服务器](#搭建文件服务器) + - [解决跨域](#解决跨域) +- [资源](#资源) + + + +## 一、Nginx 简介 **什么是 Nginx?** **Nginx (engine x)** 是一款轻量级的 Web 服务器 、反向代理服务器及电子邮件(IMAP/POP3)代理服务器。 -

+![img](http://dunwu.test.upcdn.net/cs/web/nginx/nginx.jpg!zp) **什么是反向代理?** 反向代理(Reverse Proxy)方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。 -

+![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 也可以实现简单的负载均衡功能。 -

+![](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 配置生成器 diff --git a/docs/coverpage.md b/docs/coverpage.md index 51fe4e3..3d20c98 100644 --- a/docs/coverpage.md +++ b/docs/coverpage.md @@ -1,8 +1,7 @@ -
+
# nginx-tutorial -> Nginx 极简教程 +> 📚 **nginx-tutorial** 是一个 Nginx 极简教程。 [开始阅读](README.md) - diff --git a/docs/index.html b/docs/index.html index b2b2b11..5050122 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,248 +1,140 @@ - - - Nginx Tutorial - - - - - - - + + +
正在加载...
- .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; - } + + - /* content 样式内容 */ - .sidebar a, - .content a { - color: #399AB2 !important; - text-decoration: none !important; - } + - .sidebar a:hover, - .content a:hover { - color: #FE4165 !important; - text-decoration: underline !important; - } + + + - .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; - } + + + + + + + - @-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; - } - - - - - -
正在加载...
- - - - - - - - - - - - - - - + + + diff --git a/docs/nginx-install.md b/docs/nginx-install.md index 7f21a31..3d6ca16 100644 --- a/docs/nginx-install.md +++ b/docs/nginx-install.md @@ -1,16 +1,14 @@ # Nginx 安装 - + - [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)。 -

+![img](http://dunwu.test.upcdn.net/snap/20180920181023092347.png) (2)解压到本地 -

+![img](http://dunwu.test.upcdn.net/snap/20180920181023092044.png) (3)启动 @@ -144,7 +142,7 @@ $ firewall-cmd --reload 启动后,访问站点: -

+![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] +``` ## 参考资料 diff --git a/docs/nginx-quickstart.md b/docs/nginx-quickstart.md index e7a0430..0266c8e 100644 --- a/docs/nginx-quickstart.md +++ b/docs/nginx-quickstart.md @@ -1,57 +1,57 @@ # Nginx 极简教程 -> **Nginx 是一个开源的 HTTP 和反向代理服务器,一个邮件代理服务器以及一个通用的 TCP / UDP 代理服务器**。 -> > 本项目是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx。 > > [**examples**](https://github.com/dunwu/nginx-tutorial/tree/master/examples) 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果。 -## 简介 + -### 什么是 Nginx? +- [一、Nginx 简介](#一nginx-简介) +- [二、Nginx 入门](#二nginx-入门) +- [三、Nginx 实战](#三nginx-实战) + - [Http 反向代理](#http-反向代理) + - [Https 反向代理](#https-反向代理) + - [负载均衡](#负载均衡) + - [网站有多个 webapp 的配置](#网站有多个-webapp-的配置) + - [静态站点](#静态站点) + - [搭建文件服务器](#搭建文件服务器) + - [解决跨域](#解决跨域) +- [资源](#资源) -Nginx 是一种快速、轻巧且功能强大的 Web 服务器,也可以用作: + -- 快速 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) -

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

+![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 ` - 向 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 也可以实现简单的负载均衡功能。 -

+![](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 配置生成器 diff --git a/docs/sidebar.md b/docs/sidebar.md new file mode 100644 index 0000000..0775b95 --- /dev/null +++ b/docs/sidebar.md @@ -0,0 +1,6 @@ +# nginx-tutorial + +- [Nginx 快速教程](nginx-quickstart.md) +- [Nginx 安装](nginx-install.md) +- [Nginx 配置](nginx-configuration.md) +- [Nginx 问题](nginx-faq.md) diff --git a/examples/README.md b/examples/README.md index 6699c27..1fa79ec 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 -

+![img](images\nginx-demo01.png) ### Demo02 - 负载均衡示例 @@ -111,7 +111,7 @@ nginx-1.14.0 是 Nginx 的 windows 环境的 1.14.0 官方版本。之所以把 如图所示:三次访问的端口号各不相同,说明三个服务器各自均有不同机率(基于权重)被访问。 -

+![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 将请求分发到指定的服务器上。 -

+![img](images\nginx-demo03.png) ### Demo04 - 前后端分离示例 @@ -169,11 +169,11 @@ Nginx 配置文件:[demo04.conf](nginx-1.14.0/conf/conf.d/demo04.conf) 效果图: -

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

+![img](

+![img](images\nginx-demo05.png) ### Demo06 - 静态站点示例 @@ -220,4 +220,4 @@ Nginx 中的配置要点: 效果图如下: -

+![img](images\nginx-demo06.png) diff --git a/examples/javaapp/pom.xml b/examples/javaapp/pom.xml index a5390ec..3e916c8 100644 --- a/examples/javaapp/pom.xml +++ b/examples/javaapp/pom.xml @@ -14,7 +14,7 @@ ${java.version} ${java.version} 5.0.2.RELEASE - 8.5.40 + 8.5.50 diff --git a/examples/reactapp/scripts/build.sh b/examples/reactapp/scripts/build.sh index 2529388..38a6c11 100644 --- a/examples/reactapp/scripts/build.sh +++ b/examples/reactapp/scripts/build.sh @@ -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 diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..eb6bb1f --- /dev/null +++ b/prettier.config.js @@ -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 +}