From deb7d03be3f2db4d07b6002c0e8eab703b8efe10 Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Sat, 8 Oct 2022 05:02:30 +0000 Subject: [PATCH] doc: update `nginx.md` cheatsheet. 6eb1ef32603e3c010f99e48a5ddf1ef94de56962 --- docs/nginx.html | 69 +++++++++++++++++++++++++++++++++++----- docs/quickreference.html | 4 +-- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/docs/nginx.html b/docs/nginx.html index 35d70e96..85f1eccc 100644 --- a/docs/nginx.html +++ b/docs/nginx.html @@ -37,10 +37,12 @@

NGINX 备忘清单

这个 nginx 快速参考备忘单显示了它的常用命和配置使用清单。

入门

-

服务管理

+

服务管理

+
sudo systemctl status nginx # nginx当前状态
 sudo systemctl reload nginx # 重新加载 nginx
 sudo systemctl restart nginx # 重启nginx
+
 sudo nginx -t   # 检查语法
 nginx           # 启动
 nginx -s reload # 重启
@@ -48,16 +50,16 @@
 nginx -s quit   # 平滑关闭nginx
 nginx -V        # 查看nginx的安装状态,
 
+

Docker 安装

+ +
docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
+

简单代理

location / {
   proxy_pass http://127.0.0.1:3000;
   proxy_redirect      off;
   proxy_set_header    Host $host;
-  # 客户端的 IP 地址
-  proxy_set_header    X-Real-IP $remote_addr;
-  # HTTP 请求端真实的IP
-  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }
 

全局变量

@@ -763,13 +765,25 @@ # 访问 /img/ 目录下的文件时, # 会去 /var/www/image/img/ 目录下找文件 -

屏蔽 .git 等文件

- -
location ~ (.git|.gitattributes|.gitignore|.svn) {
+

屏蔽文件目录

+ +

通用备份和归档文件

+
location ~* "\.(old|orig|original|php#|php~|php_bak|save|swo|aspx?|tpl|sh|bash|bak?|cfg|cgi|dll|exe|git|hg|ini|jsp|log|mdb|out|sql|svn|swp|tar|rdf)$" {
     deny all;
 }
 
+

拒绝访问 .git.svn 目录

+
location ~ (.git|.svn) {
+    deny all;
+}
+
+ +

拒绝访问隐藏文件和目录

+
location ~ /\.(?!well-known\/) {
+    deny all;
+}
+

防盗图配置

location ~ \/public\/(css|js|img)\/.*\.(js|css|gif|jpg|jpeg|png|bmp|swf) {
@@ -779,9 +793,48 @@
   }
 }
 
+

阻止常见攻击

+ +

base64编码的网址

+
location ~* "(base64_encode)(.*)(\()" {
+    deny all;
+}
+
+

javascript eval() url

+
location ~* "(eval\()" {
+    deny all;
+}
+
+

Gzip 配置

+ +
gzip  on;
+gzip_buffers 16 8k;
+gzip_comp_level 6;
+gzip_http_version 1.1;
+gzip_min_length 256;
+gzip_proxied any;
+gzip_vary on;
+gzip_types
+    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
+    text/javascript application/javascript application/x-javascript
+    text/x-json application/json application/x-web-app-manifest+json
+    text/css text/plain text/x-component
+    font/opentype application/x-font-ttf application/vnd.ms-fontobject
+    image/x-icon;
+gzip_disable  "msie6";
+
+

使网站不可索引

+ +
add_header X-Robots-Tag "noindex";
+
+location = /robots.txt {
+  return 200 "User-agent: *\nDisallow: /\n";
+}
+

另见

© 2022 Kenny Wang, All rights reserved.
diff --git a/docs/quickreference.html b/docs/quickreference.html index 27be4099..fc4d8bdd 100644 --- a/docs/quickreference.html +++ b/docs/quickreference.html @@ -67,8 +67,8 @@
  • 内容采用 URL 参数的字符拼接方式
  • 语法

    -

    <!--rehype: + key=value + & + key=value + -->
    -标识开始 + 参数 + 分隔符 + 参数 + 标识结束

    +

    <!--rehype: + key=value + & + key=value + -->
    +标识开始 + 参数 + 分隔符(&) + 参数 + 标识结束

    示例

    ### H2 部分
     <!--rehype:body-class=cols-2-->