使用最新的 nginx,是否可以仅代理缓存特定的 html 状态代码响应?
我们对某些响应使用 410 状态代码。
这些都是根据我们的数据库进行检查的。
当所述内容被标记为永久删除(410)时,发送 410 状态代码。
此内容将永远消失。
我们只想代理缓存这些结果。
这可能吗?
我们在 nginx 代理后面使用 nginx 后端。
我们使用上游保活。
他们工作得很好。
我们想知道,我们应该keepalive_requests在后端设置什么值来将最大保活请求数设置为无限制?
谢谢!
我使用 nginx 作为带有 mod_php 的 apache 前面的反向代理。我的网站位于 https 上,需要将变量 $_SERVER['HTTPS'] 设置为“on”才能正确组装一些链接。我的网站位于 drupal 上,因此在决定网站是否在 https 下运行时,无法修复代码并检查其他变量。
有没有办法只通过调整 nginx 或 apache 配置来解决这个问题?
我发现其他人问类似的问题,但我没有找到适合我的解决方案,也没有明确声明我想要的东西是不可能的。
我有以下 Nginx 配置:
http {
...
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
...
upstream webhook_staging {
server 127.0.0.1:4001;
keepalive 64;
}
location /webhooks/incoming_mails {
client_max_body_size 60m;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
proxy_http_version 1.1;
# Does not work for HEAD requests
#>> proxy_cache one;
#>> proxy_cache_key $scheme$host$request_uri;
proxy_pass http://webhook_staging;
}
}
Run Code Online (Sandbox Code Playgroud)
上游服务器是一个常规的 Node.js 进程。如果我激活proxy_cache_*上面的指令,HEAD请求就会被传递GET到上游服务器。如果我停用指令,HEAD请求将作为请求传递HEAD,一切都很好。
有什么建议么?
谢谢!
我正在尝试让我的 Nginx 反向代理正常工作。但是,我发现一旦文件被缓存,即使后端文件发生更改,它也永远不会更新/重新验证,这可以通过ETagorLAST-Modified字段来识别。有人可以帮我解决这个问题吗?
这是我的设置:
proxy: proxy.test.com
backend: back.example.com
Run Code Online (Sandbox Code Playgroud)
nginx 设置:
proxy_cache_path /home/cache levels=1:2 keys_zone=cache_rev:16m inactive=14d max_size=12g;
proxy_cache_key "$scheme://$host$request_uri";
server {
listen 80 default_server;
resolver 74.82.42.42;
server_name proxy.test.com;
location ~ ^/ {
proxy_pass http://back.example.com$request_uri;
proxy_redirect off;
proxy_buffering on;
proxy_cache_revalidate on;
proxy_pass_header Set-Cookie;
proxy_cache cache_rev;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_valid 200 1d;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
}
}
Run Code Online (Sandbox Code Playgroud)
这是更改的curl信息before和after后端文件。
更改前index.html:
$ curl …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ARR 和 urlrewrite 部署 jetty servlet 来创建反向代理。如果我启用“在响应标头中反向重写主机”,那么一切似乎都工作正常。我通过 www.example.com/servlet 访问 servlet,该地址在浏览器中保持不变,但通过 localhost:8080 访问 servlet。
问题是该 servlet 根据 get 参数返回 302 重定向。例如,如果我访问 www.example.com/servlet?input=cleaning 那么我将得到一个 302 重定向,该重定向可能会访问 www.cleaningexample.com/howtoclean。反向重写主机规则意味着客户端不会看到此 url,而是返回 www.example.com/howtoclean。
我无法设置静态出站规则,因为我事先不知道 302 重定向可能返回哪个地址。
如果我禁用反向重写主机,则浏览器中的 URL 将从 www.example.com/servlet 更改为 localhost:8080/servlet。
我尝试替换出站规则中的主机,但找不到任何地方可以获取 servlet 返回的原始位置标头,以替换重写的位置主机。
有没有办法让它正常工作?
我想在 Nginx 中添加远程 ip 作为 Cookie,以便它可以传递给 AWS 负载均衡器以获得负载均衡器的粘性。
location / {
proxy_set_header Cookie "$http_cookie; ip=$remote_addr";
proxy_pass http://app_upstream;
}
Run Code Online (Sandbox Code Playgroud)
我使用这些来设置 cookie,但 AWS ELB 不接受它作为粘性。由于此服务器用作 iframe,因此我无法使用 ELB 生成的 cookie 进行负载平衡,以防 Safari/iOs 默认阻止 3rd 方 cookie。
我愿意放弃 nginx 并编写自定义反向代理。
我在 vps 服务器(nginx)中运行一个网站。我最近发现了其他几个与我的网站 100% 重复的网站。
即使我更改帖子或从我的服务器删除文件,这些其他网站也会自动更新我所做的更改!好像有人未经授权就有了镜像网站。出于这个原因,它真的伤害了我的 SEO 结果。
这是反向代理攻击吗?以及如何防止有人镜像我的网站?
我有下一个 NGINX 代理配置
http {
server_tokens off;
server {
listen 7443 ssl;
ssl_certificate /etc/nginx/ssl/star.crt;
ssl_certificate_key /etc/nginx/ssl/star.key;
location /prometheus/ {
auth_basic "Prometheus";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# I leave this hardcoded for now
proxy_pass http://prometheus:9090/prometheus/;
}
location / {
auth_basic "Prometheus";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# I leave this hardcoded for now
proxy_pass http://alertmanager:9093;
}
}
}
events {}
Run Code Online (Sandbox Code Playgroud)
如果我使用端口 7443 在没有指定 HTTPS 的浏览器 URL 中输入,我会得到:
The …Run Code Online (Sandbox Code Playgroud) 我需要一个专家来配置NAT重定向(iptables)来维护客户端的源地址。目前我的服务器可以工作,但所有客户端都显示我的 vLAN 的私有 IP。
我的服务器重定向的操作示例:
VPS 1 (Public IP) redirect traffic to VPS 5 (Private IP)
VPS 2 (Public IP) redirect traffic to VPS 5 (Private IP)
VPS 3 (Public IP) redirect traffic to VPS 5 (Private IP)
VPS 4 (Public IP) redirect traffic to VPS 5 (Private IP)
Run Code Online (Sandbox Code Playgroud)
但是在重定向流量时,会将客户端的 IP 更改为客户端访问的公共服务器的私有 IP。
TCPDUMP:
IP 10.0.1.130.61570> 10.0.1.138.85: UDP, length 35
IP 10.0.1.132.63112> 10.0.1.138.85: UDP, length 35
IP 10.0.1.133.63435> 10.0.1.138.85: UDP, length 35
IP 10.0.1.136.63432> 10.0.1.138.85: UDP, length 35
Run Code Online (Sandbox Code Playgroud)
这是重定向完成后所有客户端都分配了私有IP的问题,我需要维护客户端的真实IP。
如果我删除规则“iptables …
reverse-proxy ×10
nginx ×8
amazon-elb ×1
apache-2.2 ×1
arr ×1
cache ×1
cookies ×1
drupal ×1
http-cookie ×1
https ×1
iis ×1
iptables ×1
keepalive ×1
linux ×1
networking ×1
node.js ×1
rewrite ×1
routing ×1
security ×1
vps ×1