{ "version": "https://jsonfeed.org/version/1", "title": "涛声依旧", "subtitle": "天下事有难易乎?为之,则难者亦易矣", "icon": "https://blog.jingxiyuan.cn/images/favicon.ico", "description": "天生我材必有用", "home_page_url": "https://blog.jingxiyuan.cn", "items": [ { "id": "https://blog.jingxiyuan.cn/2022/11/08/Nginx%E9%85%8D%E7%BD%AE-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86/", "url": "https://blog.jingxiyuan.cn/2022/11/08/Nginx%E9%85%8D%E7%BD%AE-%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86/", "title": "Nginx配置-反向代理", "date_published": "2022-11-08T02:05:00.000Z", "content_html": "
正向代理:如果把局域网外的 Internet 想象成一个巨大的资源库,则局域网中的客户端要访问 Internet,则需要通过代理服务器来访问,这种代理服务就称为正向代理,下面是正向代理的原理图。
\n
\n 反向代理:看下面原理图,就一目了然。其实客户端对代理是无感知的,因为客户端不需要任何配置就可以访问,我们只需要将请求发送到反向代理服务器,由反向代理服务器去选择目标服务器获取数据后,在返回给客户端,此时反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器 IP 地址。
\n
\n\n正向代理和反向代理的区别,一句话就是:如果我们客户端自己用,就是正向代理。如果是在服务器用,用户无感知,就是反向代理。
\n
在学习 Nginx 之前,要熟知它的配置文件,毕竟,下面需要做的所有配置(反向代理、负载均衡、动静分离等),都是基于它的配置文件。
\nNginx 默认的配置文件是在安装目录下的 conf 目录下,后续对 Nginx 的使用基本上都是对此配置文件进行相应的修改。完整的配置文件,可以看一下文章最后。修改过 nginx.conf 配置文件,记得要✔️重启 Nginx 服务(☆☆☆☆☆)
\n配置文件中有很多 #号,该符号表示注释内容,去掉所有以 #开头的段落,精简之后的配置文件内容如下(PS:其实注释掉的地方,都是一些功能的使用代码,需要用到的时候,取消注释即可):
\n# 主进程叫 master,负责管理子进程,子进程叫 worker | |
# worker_processes 配置项表示开启几个业务进程,一般和 cpu 核数有关 | |
worker_processes 1; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
\t# include 表示可以引入其他文件,此处表示引入 http mime 类型 | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
keepalive_timeout 65; | |
\t# 虚拟主机,可以配置多个 | |
server { | |
listen 80; | |
server_name localhost; | |
location / { | |
\t# 路径匹配之后,哪个目录下去匹配相应的网页,html 是相对路径 | |
root html; | |
index index.html index.htm; | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
\t} | |
} |
\n\n去掉注释信息后,可以将 nginx.conf 配置文件分为三部分:
\n
worker_processes 1; |
从配置文件开始到 events 块之间的内容,主要会设置一些影响 Nginx 服务器整体运行的配置指令,主要包括:配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。
\n上面这行 worker_processes 配置,是 Nginx 服务器并发处理服务的关键配置,该值越大,可以支持的并发处理量也越多,但是会受到硬件、软件等设备的约束。
\nevents { | |
\tworker_connections 1024; | |
} |
\n\n上述例子就表示每个 work process 支持的最大连接数为 1024。这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活配置。
\n
http { | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
keepalive_timeout 65; | |
server { | |
listen 80; | |
server_name localhost; | |
location / { | |
root html; | |
index index.html index.htm; | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} |
http 全局块:http 全局块配置的指令包括:文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。
\nserver 块:这块和虚拟主机有密切关系,从用户角度看,虚拟主机和一台独立的硬件主机是完全一样的,该技术的产生是为了节省互联网服务器硬件成本。
\nlocation 块:这块的主要作用是:基于 Nginx 服务器接收到的请求字符串(例如 server_name/uri-string),对虚拟主机名称(也可以是 IP 别名)之外的字符串(例如 前面的 /uri-string)进行匹配,对特定的请求进行处理。地址定向、数据缓存和应答控制等功能,还有许多第三方模块的配置也在这里进行。
\n\n\n每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机。而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。(☆☆☆☆☆)
\n
location [ = | ~ | ~* | ^~ | @ ] /uri { | |
} | |
= :用于不含正则表达式的 uri 前,要求请求字符串与 uri 严格匹配,如果匹配成功,就停止继续向下搜索并立即处理该请求。 | |
~ :用于表示 uri 包含正则表达式,并且区分大小写。 | |
~* :用于表示 uri 包含正则表达式,并且不区分大小写。 | |
^~ :用于不含正则表达式的 uri 前,要求 Nginx 服务器找到标识 uri 和请求字符串匹配度最高的location后,立即使用此 location 处理请求,而不再使用 location 块中的正则 uri 和请求字符串做匹配。 | |
@ : \"@\" 定义一个命名的 location,使用在内部定向时,例如 error_page | |
/uri :不带任何修饰符,也表示前缀匹配,但是在正则匹配之后,如果没有正则命中,命中最长的规则 | |
/ :通用匹配,任何未匹配到其它location的请求都会匹配到,相当于switch中的default | |
[☆☆☆☆☆ uri没有“/”结尾时,location /abc/def可以匹配/abc/defghi请求,也可以匹配/abc/def/ghi等。而有“/”结尾时,location /abc/def/不能匹配/abc/defghi请求,只能匹配/abc/def/anything这样的请求]{.red} |
[url结尾加上了/]{.red},相当于是绝对路径,则Nginx不会把location中匹配的路径部分加入代理uri。 | |
[url结尾不加/]{.red},Nginx则会把匹配的路径部分加入代理uri。 | |
情景1: | |
proxy_pass后有/ | |
访问地址:http://localhost:8081/WCP.Service/wcp/modeladapter/download/asc.shtml | |
最终代理:http://10.194.171.7:13082/modeladapter/download/asc.shtml | |
location /WCP.Service/wcp/modeladapter/download/ { | |
\tproxy_pass http://10.194.171.7:13082/modeladapter/download/; | |
} | |
访问地址:http://localhost:8081/model/asc.shtml | |
最终代理:http://127.0.0.1:8082/model/asc.shtml | |
location /model/ { | |
\tproxy_pass http://127.0.0.1:8082/model/; | |
} | |
情景2: | |
proxy_pass后有/ | |
访问地址:http://localhost:8081/model/asc.shtml | |
最终代理:http://127.0.0.1:8082/asc.shtml | |
location /model/ { | |
\tproxy_pass http://127.0.0.1:8082/; | |
} | |
情景3: | |
proxy_pass后没有/ | |
访问地址:http://localhost:8081/model/asc.shtml | |
最终代理:http://127.0.0.1:8082/model/asc.shtml | |
location /model/ { | |
\tproxy_pass http://127.0.0.1:8082; | |
} | |
情景4 | |
proxy_pass后没有/ | |
访问地址:http://localhost:8081/model/asc.shtml | |
最终代理:http://127.0.0.1:8082/AAAmodel/asc.shtml | |
location /model/ { | |
\tproxy_pass http://127.0.0.1:8082/AAA; | |
} | |
情景5 | |
proxy_pass后有/ | |
访问地址:http://localhost:8081/model/asc.shtml | |
最终代理:http://127.0.0.1:8082/asc.shtml | |
location /model { | |
\tproxy_pass http://127.0.0.1:8082/; | |
} | |
情景6 | |
proxy_pass后有/ | |
访问地址:http://localhost:8081/modelBBB/asc.shtml | |
最终代理:http://127.0.0.1:8082/asc.shtml | |
location /model { | |
\tproxy_pass http://127.0.0.1:8082/; | |
} |
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
#log_format main '$remote_addr - $remote_user [$time_local] \"$request\" ' | |
# '$status $body_bytes_sent \"$http_referer\" ' | |
# '\"$http_user_agent\" \"$http_x_forwarded_for\"'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
server { | |
listen 80; | |
server_name localhost; | |
#charset koi8-r; | |
#access_log logs/host.access.log main; | |
location / { | |
root html; | |
index index.html index.htm; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \\.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \\.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# fastcgi_index index.php; | |
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\\.ht { | |
# deny all; | |
#} | |
} | |
# another virtual host using mix of IP-, name-, and port-based configuration | |
# | |
#server { | |
# listen 8000; | |
# listen somename:8080; | |
# server_name somename alias another.alias; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
# HTTPS server | |
# | |
#server { | |
# listen 443 ssl; | |
# server_name localhost; | |
# ssl_certificate cert.pem; | |
# ssl_certificate_key cert.key; | |
# ssl_session_cache shared:SSL:1m; | |
# ssl_session_timeout 5m; | |
# ssl_ciphers HIGH:!aNULL:!MD5; | |
# ssl_prefer_server_ciphers on; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
} |
sudo apt autoremove --purge nodejs |
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && sudo apt-get install -y nodejs |
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null | |
echo \"deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main\" | sudo tee /etc/apt/sources.list.d/yarn.list | |
sudo apt-get update && sudo apt-get install yarn |
yarn install |
yarn build |
apt install nginx |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
# SSL configuration | |
# | |
# listen 443 ssl default_server; | |
# listen [::]:443 ssl default_server; | |
# | |
# Note: You should disable gzip for SSL traffic. | |
# See: https://bugs.debian.org/773332 | |
# | |
# Read up on ssl_ciphers to ensure a secure configuration. | |
# See: https://bugs.debian.org/765782 | |
# | |
# Self signed certs generated by the ssl-cert package | |
# Don't use them in a production server! | |
# | |
# include snippets/snakeoil.conf; | |
root /var/www/html; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name _; | |
location /api { | |
proxy_pass http://localhost:8080; | |
} | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
#try_files $uri $uri/ =404; | |
alias /opt/codes/dayu-tools-arbitrage-web/dist/; | |
try_files $uri $uri/ @router; | |
index index.html index.htm; | |
} | |
location @router { | |
rewrite ^.*$ /index.html last; | |
} | |
} |
rm dist -fr | |
yarn build |
2>/dev/null |
意思就是把错误输出到 “黑洞”
\n>/dev/null 2>&1 |
默认情况是 1,也就是等同于 1>/dev/null 2>&1。意思就是把标准输出重定向到 “黑洞”,还把错误输出 2 重定向到标准输出 1,也就是标准输出和错误输出都进了 “黑洞”
\n2>&1 >/dev/null |
意思就是把错误输出 2 重定向到标准出书 1,也就是屏幕,标准输出进了 “黑洞”,也就是标准输出进了黑洞,错误输出打印到屏幕
\n文件描述符
\n Linux 系统预留三个文件描述符:0、1 和 2,他们的意义如下所示:
\n0—— 标准输入(stdin)
\n略...
\n1—— 标准输出(stdout)
\n在当前目录下,有且只有一个文件名称为 a.txt 的文件,这时我们运行这个命令【ls a.txt】, 就会获得一个标准输出 stdout 的输出结果:a.txt
\n
\n2—— 标准错误(stderr)
\n在当前目录下,有且只有一个文件名称为 a.txt 的文件,我们运行命令【ls b.txt】,我们就会获得一个标准错误 stderr 的输出结果 “ls:无法访问 b.txt:没有这样的文件或目录”。
\n
重定向
\n重定向的符号有两个:> 或 >>,两者的区别是:前者会先清空文件,然后再写入内容,后者会将重定向的内容追加到现有文件的尾部。举例如下:
重定向标准输出 stdout
\n
\n 如上图所示,对比没有添加重定向的操作,这条命令在使用之后并没有将 a.txt 打印到屏幕。在紧接的 cat 操作后,可以发现本来应该被输出的内容被记录到 stdout.txt 中。
重定向标准错误 stderr
\n
\n 如上图所示,文件描述符 2,标准错误的重定向也是同样的原理被记录在了文件 stderr.txt 这个文件里面了。
可以将 stderr 单独定向到一个文件,stdout 重定向到另一个文件
\nls b.txt 2> stderr.txt 1>stdout.txt |
ls b.txt > output.txt 2>&1 |
ls b.txt &> output.txt | |
ls b.txt >& output.txt #两个表达式效果一样的 |
\n360 全家桶众说纷纭但工具箱还是挺实用的,这波小工具可以单独下载使用,有需要的朋友赶紧下载吧!
下载地址
\n
\n
\n
win10 / win11 / 本地
\n", "tags": [ "Windows", "工具", "Windows10", "Windows11", "自动更新" ] }, { "id": "https://blog.jingxiyuan.cn/2022/10/27/%E6%9E%81%E7%A9%BA%E9%97%B4web%E7%AB%AFhttps%E7%9B%B4%E8%BF%9Enginx%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/10/27/%E6%9E%81%E7%A9%BA%E9%97%B4web%E7%AB%AFhttps%E7%9B%B4%E8%BF%9Enginx%E9%85%8D%E7%BD%AE/", "title": "极空间web端https直连nginx配置", "date_published": "2022-10-27T05:34:00.000Z", "content_html": "server { | |
\t\tif ($scheme = http) { | |
\t\t\trewrite ^(.*)$ https://$host$1 permanent; | |
\t\t} | |
} |
#极空间 - web | |
server { | |
\tlisten 10000 ssl http2; #ipv4 | |
\tlisten [::]:10000 ssl http2; #ipv6 | |
\tserver_name xxx.xxx.com; #填写自己的域名,主域名或者子域名 | |
\t#include /etc/nginx/conf.d/ssl/ssl_common.conf; | |
\tssl_certificate_key /etc/nginx/conf.d/ssl/xxx.key; #加密证书 | |
\tssl_certificate /etc/nginx/conf.d/ssl/xxx.pem; #加密证书 | |
\tssl_session_timeout 1d; | |
\tssl_session_cache shared:MozSSL:10m; | |
\tssl_session_tickets off; | |
\tssl_protocols TLSv1.2 TLSv1.3; | |
\tssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; | |
\tssl_prefer_server_ciphers on; | |
#开启 OCSP stapling | |
\tssl_stapling on; | |
\tssl_stapling_verify on; | |
\tclient_max_body_size 128M; | |
\tadd_header Strict-Transport-Security \"max-age=31536000; includeSubdomains; preload\"; | |
\tproxy_send_timeout 180s; #设置发送超时时间 | |
proxy_read_timeout 180s; #设置读取超时时间 | |
\t# Prevent Information leaks | |
\tproxy_hide_header X-Powered-By; | |
\tproxy_hide_header Server; | |
\tproxy_hide_header X-AspNetMvc-Version; | |
\tproxy_hide_header X-AspNet-Version; | |
\t# http security headers | |
\tadd_header X-Content-Type-Options nosniff; | |
\tadd_header Pragma no-cache; | |
\tadd_header Cache-Control no-store; | |
\tadd_header X-XSS-Protection \"1; mode=block\"; | |
\tadd_header Referrer-Policy origin-when-cross-origin; | |
\tadd_header X-Permitted-Cross-Domain-Policies none; | |
add_header X-Frame-Options SAMEORIGIN; #允许同域嵌套 | |
\t# Add Security cookie flags | |
\tproxy_cookie_path ~(.*) \"$1; SameSite=strict; secure; httponly\"; | |
\t# Path to the root of your installation | |
\tlocation / { | |
\t\tproxy_intercept_errors on; | |
\t\tproxy_max_temp_file_size 0; | |
\t\tproxy_set_header Host $host; | |
\t\tproxy_set_header X-Real-IP $remote_addr; | |
\t\tproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
\t\tproxy_set_header X-Forwarded-Proto $scheme; | |
\t\tproxy_pass http://极空间内网ip:5055; #这里设置你自己要跳转的局域网应用; | |
\t\tproxy_redirect http://域名:5055/home https://域名:10000/home; #极空间在登陆后会跳转到 http 协议的 5055 端口,所以要在此替换为 https 协议的 10000 端口 | |
\t} | |
\terror_page 500 502 503 504 /500.html; | |
\terror_page 400 404 /500.html; | |
\tlocation = /500.html { | |
\t\troot /usr/share/nginx/html/; #错误 html | |
\t} | |
} |
#青龙面板装载路径 | |
/ql/data | |
#博客装载路径(如果你不部署 hexo 博客可以不用配置) | |
/root/.ssh #ssh 证书文件(如果你不用把 hexo 推送到 git 上可以不用配置) | |
/blog #hexo 博客编译目录 | |
/blog/nginx_blog #nginx 上放置博客的目录(例如:/Docker/nginx/html/blog) |
4000端口是hexo-admin使用的,如果你不用可以不配置
ql repo https://github.com/KingRan/KR.git "jd_|jx_|jdCookie" "activity|backUp|wskey" "^jd[^_]|USER|utils|function|sign|sendNotify|ql|JDJR"
0 */3 * * *
名称:JD_COOKIE | |
值:web京东登陆后按F12在网络tab页中的请求内查找cookie,然后复制pt_key=到pt_pin=等 |
repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可 | |
RepoFileExtensions=\"js py ts\" | |
钉钉(消息推送) | |
export DD_BOT_TOKEN= | |
export DD_BOT_SECRET= | |
## 开卡 | |
export guaopencard_All=\"true\" | |
export guaopencard_addSku_All=\"true\" | |
export guaopencardRun_All=\"true\" | |
export guaopencard_draw=\"true\" | |
export JD_TRY=\"true\" | |
export exjxbeans=\"true\" | |
export DY_OPENALL=\"true\" | |
#抽奖 | |
export opencard_draw=3 | |
#开启脚本依赖文件缺失修复 | |
export ec_fix_dep=\"true\" | |
#开启脚本依赖文件更新 | |
export ec_re_dep=\"true\" | |
#清空购物车 | |
export JD_CART_REMOVE=\"true\" | |
export JD_CART=\"true\" | |
#去掉多余的双十一红包脚本 | |
export FLCODE='' | |
#加购物车抽奖 | |
export RUN_CAR=true | |
#停用小额免密支付 | |
export JD_PAY_CONTRACT=true |
#nodejs 依赖 | |
crypto-js\t | |
prettytable\t | |
dotenv\t | |
jsdom\t | |
date-fns\t | |
tough-cookie\t | |
tslib\t | |
ws@7.4.3\t | |
ts-md5\t | |
jsdom -g\t | |
jieba\t | |
fs\t | |
form-data\t | |
json5\t | |
global-agent\t | |
png-js\t | |
@types/node\t | |
require\t | |
typescript\t | |
js-base64\t | |
axios | |
#pythone 依赖 | |
requests\t | |
canvas\t | |
ping3\t | |
jieba\t | |
aiohttp\t | |
PyExecJS | |
#Linux 依赖 | |
bizCode | |
bizMsg | |
lxml |
#配置国内源 | |
pip config --global set global.index-url https://mirrors.aliyun.com/pypi/simple/ | |
pip config --global set install.trusted-host https://mirrors.aliyun.com | |
#升级 pip | |
pip install --upgrade pip | |
#更新青龙 | |
ql update | |
#已知要安装的依赖(不安装部分脚本任务会失败) | |
pnpm install ds | |
#一键安装所有依赖(基于 Faker 一键脚本安装的青龙 | |
可通过执行/ql/data/scripts下的QLDependency.sh脚本安装,如脚本已经更新则通过下面命令执行 | |
curl -fsSL https://git.metauniverse-cn.com/https://raw.githubusercontent.com/shufflewzc/QLDependency/main/Shell/QLOneKeyDependency.sh | sh | |
#一般出现这种错误:(缺依赖) | |
Error: Cannot find module 'xx' | |
执行pnpm install xxx | |
#一般出现这种错误:(缺文件) | |
Error: Cannot find module './xx' | |
那就是拉库命令不完整,请检查或复制完整的拉库命 | |
#Python3 依赖安装失败修复(基于 Faker 一键脚本安装的青龙) | |
curl -sS https://bootstrap.pypa.io/get-pip.py | python3 |
valine: | |
appId: 粘贴5中获取的App ID #Your_appId | |
appKey: 粘贴5中获取的App Key #Your_appkey | |
placeholder: ヽ(○´∀`)ノ♪欢迎畅所欲言 # Comment box placeholder | |
avatar: mp #默认头像设置 Gravatar style : mp, identicon, monsterid, wavatar, robohash, retro | |
pageSize: 10 # Pagination size | |
lang: zh-CN | |
visitor: true # Article reading statistic 这个要设置为 false,以免与 leancloud_visitors 突冲 | |
NoRecordIP: false # Whether to record the commenter IP | |
serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in) | |
powerMode: true | |
tagMeta: | |
visitor: 新朋友 | |
master: 博主 | |
friend: 小伙伴 | |
investor: 金主粑粑 | |
tagColor: | |
master: \"var(--color-orange)\" | |
friend: \"var(--color-aqua)\" | |
investor: \"var(--color-pink)\" | |
tagMember: | |
master: | |
# - hash of master@email.com | |
# - hash of master2@email.com | |
friend: | |
# - hash of friend@email.com | |
# - hash of friend2@email.com | |
investor: | |
# - hash of investor1@email.com |
stream { | |
\t | |
\t#极空间 - docker-mariadb | |
\tupstream mariadb { | |
\t\thash $remote_addr consistent; | |
\t\tserver mariadb的ip:端口; | |
\t} | |
\tserver { | |
\t\tlisten 监听端口; | |
\t\tproxy_connect_timeout 30s; | |
\t\tproxy_timeout 300s; | |
\t\tproxy_pass mariadb; | |
\t} | |
} |
if((!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) || (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) { | |
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; | |
$_SERVER['HTTPS'] = 'on'; | |
} |
define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp'); | |
define('FS_METHOD', 'direct'); | |
define('FS_CHMOD_DIR', 0777); | |
define('FS_CHMOD_FILE', 0777); |
chown('/var/www/html', 'www-data'); | |
chgrp('/var/www/html', 'www-data'); | |
chmod('/var/www/html/wp-content/plugins', 0777); | |
chmod('/var/www/html/wp-content/themes', 0777); | |
chmod('/var/www/html/wp-content/tmp', 0777); |
if($_GET['key'] != 'value') { | |
\theader('Location: https://www.xxx.com/'); | |
} |
一年一次的总结时间又到了,这一年前半年平平无奇,后半年惊涛骇浪。中年危机如期而遇,人身的低谷终究还是来了。很沮丧也很无助,但还是要坚强面对。人生起起伏伏,时好时坏,终归还是会好起来的。加油!加油!加油
\n!
1、请先修改脚本中的服务端IP。 | |
2、如被监控端不支持let计算命令请执行sudo dpkg-reconfigure dash命令,弹出选择窗口后选择no。 | |
3、需要在脚本同目录下创建CentOS、Ubuntu、sh和conf目录,目录下分别放置nrpe的tar安装包、监控脚本和nrpe配置文件。 | |
#!/bin/bash | |
#服务端 ip | |
SERVER_IP=10.10.10.121 | |
#安装目录 | |
INSTALL_HOME=`pwd` | |
#安装 ubuntu 版本 | |
INSTALL_UBUNTU() | |
{ | |
\tsudo apt-get update | |
\tsudo apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget openssl | |
\t | |
\tcd /tmp | |
\t#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz | |
\tcp $INSTALL_HOME/Ubuntu/nrpe.tar.gz ./ | |
\ttar xzf nrpe.tar.gz | |
\tcd /tmp/nrpe-nrpe-4.0.3/ | |
\tsudo ./configure --enable-command-args --with-ssl-lib=/usr/lib/x86_64-linux-gnu/ | |
\tsudo make all | |
\tsudo make install-groups-users | |
\tsudo make install | |
\tsudo make install-config | |
\tsudo sh -c \"echo >> /etc/services\" | |
\tsudo sh -c \"sudo echo '# Nagios services' >> /etc/services\" | |
\tsudo sh -c \"sudo echo 'nrpe 5666/tcp' >> /etc/services\" | |
\t | |
\t#判断系统是高版本还是低版本 | |
\tVERSION=`lsb_release -r --short` | |
\tIS_LOW_VERSION=`echo \"$VERSION < 15\" | bc` | |
\tif [ $IS_LOW_VERSION = 1 ]; then | |
\t\t#低版本 | |
\t\tsudo make install-init | |
\telse | |
\t\t#高版本 | |
\t\tsudo make install-init | |
\t\tsudo systemctl enable nrpe.service | |
\tfi | |
\t | |
\tsudo mkdir -p /etc/ufw/applications.d | |
\tsudo sh -c \"echo '[NRPE]' > /etc/ufw/applications.d/nagios\" | |
\tsudo sh -c \"echo 'title=Nagios Remote Plugin Executor' >> /etc/ufw/applications.d/nagios\" | |
\tsudo sh -c \"echo 'description=Allows remote execution of Nagios plugins' >> /etc/ufw/applications.d/nagios\" | |
\tsudo sh -c \"echo 'ports=5666/tcp' >> /etc/ufw/applications.d/nagios\" | |
\tsudo ufw allow NRPE | |
\tsudo ufw reload | |
\t | |
\tsudo sh -c \"sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg\" | |
\t | |
\tcd $INSTALL_HOME | |
\tsudo cp ./sh/* /usr/local/nagios/libexec/ | |
\tsudo chmod +xr /usr/local/nagios/libexec/* | |
\t | |
\tsudo sh -c \"echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \\$ARG1\\$' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tNETWORK_INDEX=1 | |
\tfor NETWORK_NAME in `cat /proc/net/dev | awk '{i++; if(i>2){print $1}}' | sed 's/^[\\t]*//g' | sed 's/[:]*$//g'`;do | |
\t\t\tif [ $NETWORK_NAME != 'lo' ]; then | |
\t\t\t\t\tsudo sh -c \"echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\t\t\t\t\tNETWORK_INDEX=`expr $NETWORK_INDEX + 1 ` | |
\t\t\tfi | |
\tdone | |
\t | |
\tif [ $IS_LOW_VERSION = 1 ]; then | |
\t\t#低版本 | |
\t\tsudo start nrpe | |
\telse | |
\t\t#高版本 | |
\t\tsudo systemctl start nrpe.service | |
\tfi | |
} | |
#安装 centos 版本 | |
INSTALL_CENTOS() | |
{ | |
\tyum install -y gcc glibc glibc-common openssl openssl-devel perl wget | |
\tcd /tmp | |
\t#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-4.0.3.tar.gz | |
\tcp $INSTALL_HOME/CentOS/nrpe.tar.gz ./ | |
\ttar xzf nrpe.tar.gz | |
\tcd /tmp/nrpe-nrpe-4.0.3/ | |
\t./configure --enable-command-args | |
\tmake all | |
\tmake install-groups-users | |
\tmake install | |
\tmake install-config | |
\techo >> /etc/services | |
\techo '# Nagios services' >> /etc/services | |
\techo 'nrpe 5666/tcp' >> /etc/services | |
\t | |
\t#判断系统是高版本还是低版本 | |
\tVERSION=`rpm -q centos-release|cut -d- -f3` | |
\t#安装 bc 命令 | |
\tyum -y install bc | |
\tIS_LOW_VERSION=`echo \"$VERSION < 7\" | bc` | |
\tif [ $IS_LOW_VERSION = 1 ]; then | |
\t\t#低版本 | |
\t\tmake install-init | |
\t\t | |
\t\tiptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT | |
\t\tservice iptables save | |
\t\tip6tables -I INPUT -p tcp --destination-port 5666 -j ACCEPT | |
\t\tservice ip6tables save | |
\telse | |
\t\t#高版本 | |
\t\tmake install-init | |
\t\tsystemctl enable nrpe.service | |
\t\t | |
\t\tfirewall-cmd --zone=public --add-port=5666/tcp | |
\t\tfirewall-cmd --zone=public --add-port=5666/tcp --permanent | |
\tfi | |
\t | |
\tsudo sh -c \"sed -i '/^allowed_hosts=/s/$/,$SERVER_IP/' /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' /usr/local/nagios/etc/nrpe.cfg\" | |
\t | |
\tcd $INSTALL_HOME | |
\tsudo cp ./sh/* /usr/local/nagios/libexec/ | |
\tsudo chmod +xr /usr/local/nagios/libexec/* | |
\t | |
\tsudo sh -c \"echo 'command[check_ping]=/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_mem]=/usr/local/nagios/libexec/check_mem.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_my_service]=/usr/local/nagios/libexec/check_my_service.sh \\$ARG1\\$' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tsudo sh -c \"echo 'command[check_system_info]=/usr/local/nagios/libexec/check_system_info.sh' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\tNETWORK_INDEX=1 | |
\tfor NETWORK_NAME in `cat /proc/net/dev | awk '{i++; if(i>2){print $1}}' | sed 's/^[\\t]*//g' | sed 's/[:]*$//g'`;do | |
\t\t\tif [ $NETWORK_NAME != 'lo' ]; then | |
\t\t\t\t\tsudo sh -c \"echo 'command[check_network$NETWORK_INDEX]=/usr/local/nagios/libexec/check_network.sh $NETWORK_NAME' >> /usr/local/nagios/etc/nrpe.cfg\" | |
\t\t\t\t\tNETWORK_INDEX=`expr $NETWORK_INDEX + 1 ` | |
\t\t\tfi | |
\tdone | |
\t | |
\tif [ $IS_LOW_VERSION = 1 ]; then | |
\t\t#低版本 | |
\t\tif [ $(echo \"$VERSION < 6\" | bc) -eq 1 ]; then | |
\t\t\tservice nrpe start | |
\t\telse | |
\t\t\tstart nrpe | |
\t\tfi | |
\telse | |
\t\t#高版本 | |
\t\tsystemctl start nrpe.service | |
\tfi | |
} | |
#安装其它版本 | |
INSTALL_OTHER() | |
{ | |
\techo \"Not supported at the moment.\" | |
} | |
#根据不同系统安装不同版本 | |
INSTALL() | |
{ | |
\tif grep -Eqii \"CentOS\" /etc/issue || grep -Eq \"CentOS\" /etc/*-release; then | |
\t\tDISTRO='CentOS' | |
PM='yum' | |
\t\tINSTALL_CENTOS | |
elif grep -Eqi \"Red Hat Enterprise Linux Server\" /etc/issue || grep -Eq \"Red Hat Enterprise Linux Server\" /etc/*-release; then | |
DISTRO='RHEL' | |
PM='yum' | |
\t\tINSTALL_OTHER | |
elif grep -Eqi \"Aliyun\" /etc/issue || grep -Eq \"Aliyun\" /etc/*-release; then | |
DISTRO='Aliyun' | |
PM='yum' | |
\t\tINSTALL_OTHER | |
elif grep -Eqi \"Fedora\" /etc/issue || grep -Eq \"Fedora\" /etc/*-release; then | |
DISTRO='Fedora' | |
PM='yum' | |
\t\tINSTALL_OTHER | |
elif grep -Eqi \"Debian\" /etc/issue || grep -Eq \"Debian\" /etc/*-release; then | |
DISTRO='Debian' | |
PM='apt' | |
\t\tINSTALL_OTHER | |
elif grep -Eqi \"Ubuntu\" /etc/issue || grep -Eq \"Ubuntu\" /etc/*-release; then | |
DISTRO='Ubuntu' | |
PM='apt' | |
\t\tINSTALL_UBUNTU | |
elif grep -Eqi \"Raspbian\" /etc/issue || grep -Eq \"Raspbian\" /etc/*-release; then | |
DISTRO='Raspbian' | |
PM='apt' | |
\t\tINSTALL_OTHER | |
else | |
echo \"unknow linux.\" | |
exit 1 | |
fi | |
echo $DISTRO | |
} | |
INSTALL | |
exit 0 |
地址:http:// 服务器 IP/nagios
\n 用户名:nagiosadmin
\n 密码:nagiosadmin
#!/bin/bash | |
sudo rm -f /usr/local/nagios/var/ndo2db.pid | |
sudo rm -f /usr/local/nagios/var/ndo.sock | |
sudo systemctl restart ndo2db.service | |
sudo systemctl status ndo2db.service |
port 6379 | |
requirepass 123456(密码,建议不设置) | |
vm-enabled no (虚拟内存,内存够的情况下可以不使用) | |
maxmemory 1GB(告诉Redis当使用了多少物理内存后就开始拒绝后续的写入) | |
bind 127.0.0.1 (注释掉,否则不能外部连接) | |
rdbchecksum no(持久化数据检查) | |
list-max-ziplist-size 1024(ziplist的最大容量,正数为自己指定的大小。负数-1到-5为对应的值4到64Kb) | |
list-compress-depth 20(quicklist的两端多少个node不压缩,0为全部不压缩) |
sysctl vm.overcommit_memory=1 (立即生效) | |
修改/etc/sysctl.conf添加vm.overcommit_memory=1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何。Redis的RDB持久化实现是folk一个子进程,然后让子进程将内存镜像dump到RDB文件中。理论上来说是需要跟父进程一样的内存空间,但是由于linux很早就支持的copy-on-write技术,所以实际上并不需要这么多的物理内存的。) |
需要sudo su 切换到root身份(sudo 没用) | |
echo never > /sys/kernel/mm/transparent_hugepage/enabled | |
修改/etc/init.d/redis-server,加入/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled |
sysctl net.core.somaxconn=1024(立即生效) | |
修改/etc/sysctl.conf添加net.core.somaxconn=1024 |
客户端的输出缓冲区的限制,因为某种原因客户端从服务器读取数据的速度不够快,可用于强制断开连接(一个常见的原因是一个发布 / 订阅客户端消费消息的速度无法赶上生产它们的速度)。 | |
可以三种不同客户端的方式进行设置: | |
normal -> 正常客户端 | |
slave -> slave 和 MONITOR 客户端 | |
pubsub -> 至少订阅了一个 pubsub channel 或 pattern 的客户端 | |
语法 : | |
client-output-buffer-limit <class><hard limit> <soft limit> <soft seconds> | |
一旦达到硬限制客户端会立即断开,或者达到软限制并保持达成的指定秒数(连续)。 | |
例如,如果硬限制为 32 兆字节和软限制为 16 兆字节 /10 秒,客户端将会立即断开。如果输出缓冲区的大小达到 32 兆字节,客户端达到 16 兆字节和连续超过了限制 10 秒,也将断开连接。默认 normal 客户端不做限制,因为他们在一个请求后未要求时(以推的方式)不接收数据, | |
只有异步客户端可能会出现请求数据的速度比它可以读取的速度快的场景。 | |
把硬限制和软限制都设置为 0 来禁用该特性 | |
client-output-buffer-limit normal 0 0 0 | |
client-output-buffer-limit slave 5gb 512mb 60 | |
client-output-buffer-limit pubsub 32mb 8mb 60 |
---关闭RDB持久化--- | |
save \"\" | |
默认配置如下: | |
save 900 1 #900 秒内有 1 次更新就持久化 | |
save 300 10 #300 秒内有 10 次更新就持久化 | |
save 60 10000 #60 秒内有 10000 次更新就持久化 | |
---关闭RDB持久化--- | |
主从同步支持两种策略,即disk和socket方式。 | |
新的slave端和重连的salve端不允许去继续同步进程,这被称之为“完全同步”。 | |
一个RDB文件从master端传到slave端,分为两种情况: | |
1、支持disk:master端将RDB file写到disk,稍后再传送到slave端; | |
2、无磁盘diskless:master端直接将RDB file传到slave socket,不需要与disk进行交互。无磁盘diskless方式适合磁盘读写速度慢但网络带宽非常高的环境。 | |
repl-diskless-sync no 默认不使用diskless同步方式 | |
repl-diskless-sync-delay 30 无磁盘diskless方式在进行数据传递之前会有一个时间的延迟,以便slave端能够进行到待传送的目标队列中,这个时间默认是5秒 | |
repl-ping-slave-period 60 slave端向server端发送pings的时间区间设置,默认为10秒 | |
repl-timeout 3600 设置超时时间 | |
repl-disable-tcp-nodelay no 是否启用TCP_NODELAY,如果启用则会使用少量的TCP包和带宽去进行数据传输到slave端,当然速度会比较慢;如果不启用则传输速度比较快,但是会占用比较多的带宽。 | |
repl-backlog-size 1mb 设置backlog的大小,backlog是一个缓冲区,在slave端失连时存放要同步到slave的数据,因此当一个slave要重连时,经常是不需要完全同步的,执行局部同步就足够了。 | |
backlog设置的越大,slave可以失连的时间就越长。 | |
repl-backlog-ttl 3600 如果一段时间后没有slave连接到master,则backlog size的内存将会被释放。如果值为0则表示永远不释放这部份内存。 | |
slave-priority 100 slave端的优先级设置,值是一个整数,数字越小表示优先级越高。当master故障时将会按照优先级来选择slave端进行恢复,如果值设置为0,则表示该slave永远不会被选择。 | |
min-slaves-to-write 3 | |
min-slaves-max-lag 10 设置当一个master端的可用slave少于N个,延迟时间大于M秒时,不接收写操作。 |
基本配置同主服务一致 | |
slaveof 127.0.0.1 6379(主redis的ip和端口) | |
masterauth 123456 (主redis的密码) | |
可以通过slaveof no one命令将Slaver升级为Maste | |
bgsave (持久化命令,在redis-cli中执行,默认创建dump.rdb文件,路径为 /var/lib/redis/dump.rdb。可通过find / -name dump.rd查找) |
看状态 | |
sudo /etc/init.d/redis-server status | |
看端口 | |
netstat -nlt|grep 6379 | |
外部连接 | |
sudo vim /etc/redis/redis.conf把protected-mode改为no,把bind ip注释掉 | |
重启 | |
sudo server redis-server restart | |
查看内存 | |
free -m | |
批量删除指定key | |
redis-cli -n 6 scan 0 match *2020-06-12 count 10000| xargs redis-cli -n 6 del | |
大量删除key后快速释放被占用的内存 | |
memory purge |
写入问题 | |
redis-cli config set stop-writes-on-bgsave-error no | |
sudo vim /etc/redis/redis.conf把stop-writes-on-bgsave-error改为no | |
修改系统 sudo vim /etc/sysctl.conf加入vm.overcommit_memory=1 | |
sudo sysctl vm.overcommit_memory=1 |
在 A 域名的页面向 B 域名提交数据时需要代入 B 域名的 cookie,否则 B 域名会跳转到登陆页面。解决方式需要使用到 nginx 反向代理,配置如下:
\nserver { | |
\tlisten port ssl http2; | |
\tserver_name xxx.com; | |
\tssl_certificate_key /xxx.key; | |
\tssl_certificate /xxx.pem; | |
\tproxy_cookie_path ~(.*) \"$1; SameSite=None; secure; httponly\"; | |
\tlocation / { | |
\t\t#允许镶套的方式(可以同域镶套、指定域名镶套或者所有域名镶套) | |
\t\tadd_header X-Frame-Options ALLOWALL; #允许被所有域名镶套 | |
\t\tproxy_pass http://xxx; | |
\t} | |
} |
PicGo 是一款开源的图床管理工具,十分流行。
\nPicGo 官方指南:PicGo | PicGo
\n安装插件(需要先安装 NodeJS)
\n
图床配置
\nurl 后缀必须用红线圈中的部分,key 在 chevereto 登陆后 api 配置中查找
\n
首先安装好 svn 和 git 工具。
\n1、 到 svn 项目目录右键选中 gitbash 打开窗口,执行获取用户并映射成 git 样式账号命令如下:
\n svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > users.txt
然后会在目录下生成文件 users.txt 样式如:zhansan = 张三 zhansan@xxx.com。
\n2、新建个文件夹,将生成的 users.txt 放入新建的文件夹,然后在新建的文件夹中右键选中 gitbash 弹出窗口后执行下面命令(https://svn_project_url/ 为 svn 库的 url),拉取 svn 代码到本地新建文件夹中。
\n git svn clone https://svn_project_url/ --no-metadata --no-minimize-url --authors-file=users.txt
1、在 gitbash 窗口 cd 到 git 项目文件夹中执行以下命令把 git 仓库地址加入到 remote 中(https://git_project_url/ 为 git 库的 url)。
\n git remote add origin https://git_project_url/
2、push 项目到 git 库中。
\n git push origin master
X-Frame-Options HTTP 响应头是用来给浏览器指示允许一个页面可否在,或者 中展现的标记。网站可以使用此功能,来确保自己网站的内容没有被嵌套到别人的网站中去,也从而避免了点击劫持 (clickjacking) 的攻击。
\nX-Frame-Options 三个参数:
1、 DENY
\n表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。
\n2、SAMEORIGIN
\n表示该页面可以在相同域名页面的 frame 中展示。
\n3、ALLOW-FROM uri
\n表示该页面可以在指定来源的 frame 中展示。
\n4、ALLOWALL
\n表示该页面可以在任何来源的 frame 中展示。
\n换一句话说,如果设置为 DENY,不光在别人的网站 frame 嵌入时会无法加载,在同域名页面中同样会无法加载。另一方面,如果设置为 SAMEORIGIN,那么页面就可以在同域名页面的 frame 中嵌套。正常情况下我们通常使用 SAMEORIGIN 参数。
\n需要把下面这行添加到'site' 的配置中
\n Header always append X-Frame-Options SAMEORIGIN
需要添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置项中,个人来讲喜欢配置在‘server’ 中
\n 正常情况下都是使用 SAMEORIGIN 参数,允许同域嵌套
\n add_header X-Frame-Options SAMEORIGIN;
允许单个域名 iframe 嵌套
\n add_header X-Frame-Options ALLOW-FROM http://xxx.com/;
允许多个域名 iframe 嵌套,注意这里是用逗号分隔
\n add_header X-Frame-Options "ALLOW-FROM http://xxx.com/,https://xxx.com/";
允许任何域名 iframe 嵌套
\n add_header X-Frame-Options ALLOWALL;
在‘conf/web.xml’填加以下配置
\n<filter> | |
<filter-name>httpHeaderSecurity</filter-name> | |
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class> | |
<init-param> | |
<param-name>antiClickJackingOption</param-name> | |
<param-value>SAMEORIGIN</param-value> | |
</init-param> | |
<async-supported>true</async-supported> | |
</filter> | |
<filter-mapping> | |
<filter-name>httpHeaderSecurity</filter-name> | |
<url-pattern>/*</url-pattern> | |
<dispatcher>REQUEST</dispatcher> | |
<dispatcher>FORWARD</dispatcher> | |
</filter-mapping> |
添加下面的配置到 ‘Web.config’文件中
\n<system.webServer> | |
<httpProtocol> | |
<customHeaders> | |
<add name=\"X-Frame-Options\" value=\"SAMEORIGIN\" /> | |
</customHeaders> | |
</httpProtocol> | |
</system.webServer> |
一个月都过去了,工作还没有着落!
\n", "tags": [ "生活", "心情", "心情", "郁闷" ] }, { "id": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/", "url": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/", "title": "nginx负载均衡配置", "date_published": "2022-09-27T06:45:00.000Z", "content_html": "每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器 down 掉,能自动剔除。
\nupstream my_server { | |
\tserver 192.168.0.2:8080; | |
\tserver 192.168.0.3:8080; | |
} | |
server { | |
\tlisten 80; | |
\tserver_name 192.168.0.1; | |
\t# Path to the root of your installation | |
\tlocation / { | |
\t\tproxy_pass http://my_server; | |
\t} | |
\t | |
} |
weight 代表权重,默认为 1,权重越高被分配的客户端越多,指定轮询几率。weight 和访问比率成正比,用于后端服务器性能不均的情况。
\nupstream my_server { | |
\tserver 192.168.0.2:8080 weight=1; | |
\tserver 192.168.0.3:8080 weight=2; | |
} | |
server { | |
\tlisten 80; | |
\tserver_name 192.168.0.1; | |
\t# Path to the root of your installation | |
\tlocation / { | |
\t\tproxy_pass http://my_server; | |
\t} | |
\t | |
} |
每个请求按访问 ip 的 hash 结果分配,这样每个访客固定访问一个后端服务器,可以解决 session 的问题。
\nupstream my_server { | |
\tip_hash; | |
\tserver 192.168.0.2:8080; | |
\tserver 192.168.0.3:8080; | |
} | |
server { | |
\tlisten 80; | |
\tserver_name 192.168.0.1; | |
\t# Path to the root of your installation | |
\tlocation / { | |
\t\tproxy_pass http://my_server; | |
\t} | |
\t | |
} |
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
\nupstream my_server { | |
\tserver 192.168.0.2:8080; | |
\tserver 192.168.0.3:8080; | |
\tfair; | |
} | |
server { | |
\tlisten 80; | |
\tserver_name 192.168.0.1; | |
\t# Path to the root of your installation | |
\tlocation / { | |
\t\tproxy_pass http://my_server; | |
\t} | |
\t | |
} |
把静态的资源,比如图片,css,js 等先加载到 Nginx 的服务器里。
\n", "tags": [ "Linux", "服务", "Nginx", "nginx", "负载均衡" ] } ] }