From 8b1dc944360e66cf8db7d47e43e695463ab1c41e Mon Sep 17 00:00:00 2001 From: 7Wate Date: Mon, 8 Aug 2022 16:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E7=BB=B4=EF=BC=9ANginx=20=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/开发者工具/命令行的艺术.md | 2 +- docusaurus.config.js | 2 +- wiki/ops/Nginx/Nginx 常用配置.md | 138 +++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 wiki/ops/Nginx/Nginx 常用配置.md diff --git a/docs/开发者工具/命令行的艺术.md b/docs/开发者工具/命令行的艺术.md index 471cf54c..de60af9e 100644 --- a/docs/开发者工具/命令行的艺术.md +++ b/docs/开发者工具/命令行的艺术.md @@ -6,7 +6,7 @@ data: 2022年8月5日 熟练使用命令行是一种常常被忽视,或被认为难以掌握的技能,但实际上,它会提高你作为工程师的灵活性以及生产力。本文是一份我在 Linux 上工作时,发现的一些命令行使用技巧的摘要。有些技巧非常基础,而另一些则相当复杂,甚至晦涩难懂。这篇文章并不长,但当你能够熟练掌握这里列出的所有技巧时,你就学会了很多关于命令行的东西了。 -这篇文章是[许多作者和译者](AUTHORS.md)共同的成果。这里的部分内容[首次](http://www.quora.com/What-are-some-lesser-known-but-useful-Unix-commands)[出现](http://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix)于 [Quora](http://www.quora.com/What-are-some-time-saving-tips-that-every-Linux-user-should-know),但已经迁移到了 Github,并由众多高手做出了许多改进。如果你在本文中发现了错误或者存在可以改善的地方,请[**贡献你的一份力量**](/CONTRIBUTING.md)。 +这篇文章是许多作者和译者共同的成果。这里的部分内容[首次](http://www.quora.com/What-are-some-lesser-known-but-useful-Unix-commands)[出现](http://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix)于 [Quora](http://www.quora.com/What-are-some-time-saving-tips-that-every-Linux-user-should-know),但已经迁移到了 Github,并由众多高手做出了许多改进。如果你在本文中发现了错误或者存在可以改善的地方,请贡献你的一份力量。 ## 前言 diff --git a/docusaurus.config.js b/docusaurus.config.js index d64cd357..95f4bf87 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -297,7 +297,7 @@ const config = { theme: lightCodeTheme, darkTheme: darkCodeTheme, defaultLanguage: "markdown", - additionalLanguages: ["java", "git"], + additionalLanguages: ["java", "git","nginx"], }, }), }; diff --git a/wiki/ops/Nginx/Nginx 常用配置.md b/wiki/ops/Nginx/Nginx 常用配置.md new file mode 100644 index 00000000..2a9a3fdc --- /dev/null +++ b/wiki/ops/Nginx/Nginx 常用配置.md @@ -0,0 +1,138 @@ +--- +id: Nginx 常用配置 +title: Nginx 常用配置 +data: 2022年08月08日 +--- + + +在线配置网站: + +## 侦听端口 + +```nginx +server { +# Standard HTTP Protocol +listen 80; +# Standard HTTPS Protocol +listen 443 ssl; +# For http2 +listen 443 ssl http2; +# Listen on 80 using IPv6 +listen [::]:80; +# Listen only on using IPv6 +listen [::]:80 ipv6only=on; +} +``` + +## 访问日志 + +```nginx +server { +# Relative or full path to log file +access_log /path/to/file.log; +# Turn 'on' or 'off' +access_log on; +} +``` + +## 域名 + +```nginx +server { +# Listen to yourdomain.com +server_name yourdomain.com; +# Listen to multiple domains server_name yourdomain.com www.yourdomain.com; +# Listen to all domains +server_name *.yourdomain.com; +# Listen to all top-level domains +server_name yourdomain.*; +# Listen to unspecified Hostnames (Listens to IP address itself) +server_name ""; +} +``` + +## 静态资产 + +```nginx +server { +listen 80; +server_name yourdomain.com; +location / { +root /path/to/website; +} +} +``` + +## 重定向 + +```nginx +server { +listen 80; +server_name www.yourdomain.com; +return 301 http://yourdomain.com$request_uri; +} +server { +listen 80; +server_name www.yourdomain.com; +location /redirect-url { +return 301 http://otherdomain.com; +} +} +``` + +## 反向代理 + +```nginx +server { +listen 80; +server_name yourdomain.com; +location / { +proxy_pass http://0.0.0.0:3000; +# where 0.0.0.0:3000 is your application server (Ex: node.js) bound on 0.0.0.0 listening on port 3000 +} +} +``` + +## 负载均衡 + +```nginx +upstream node_js { +server 0.0.0.0:3000; +server 0.0.0.0:4000; +server 123.131.121.122; +} +server { +listen 80; +server_name yourdomain.com; +location / { +proxy_pass http://node_js; +} +} +``` + +## SSL 协议 + +```nginx +server { +listen 443 ssl; +server_name yourdomain.com; +ssl on; +ssl_certificate /path/to/cert.pem; +ssl_certificate_key /path/to/privatekey.pem; +ssl_stapling on; +ssl_stapling_verify on; +ssl_trusted_certificate /path/to/fullchain.pem; +ssl_protocols TLSv1 TLSv1.1 TLSv1.2; +ssl_session_timeout 1h; +ssl_session_cache shared:SSL:50m; +add_header Strict-Transport-Security max-age=15768000; +} +# Permanent Redirect for HTTP to HTTPS +server +{ +listen 80; +server_name yourdomain.com; +return 301 https://$host$request_uri; +} +``` +