是否可以根据上游代理的响应更改后备 error_page?
upstream serverA {
server servera.com;
}
upstream serverB {
server serverb.com;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
proxy_set_header Host $host;
proxy_pass http://serverA;
proxy_intercept_errors on;
# if serverA returns 'hard' 404
# IE returns X-HARD-404=true header
return 404;
# else I would like to fallback to server-b
error_page 403 404 500 502 504 = @serverB;
}
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是我们的设置存在问题。通常我们向服务器 a 发送请求,如果返回 404,我们会要求服务器 b 返回页面。在这种情况下,我们不希望 server-b 返回其页面,并且我们希望显式返回 404,而不尝试 server-b。
我在 Apache 2.4 服务器前面使用 nginx 作为 TLS 终止符。
我add_header X-Content-Type-Options nosniff;在 nginx 中使用此标头添加到每个响应中。
如果 Apache 返回的 HTTP 状态代码低于 400,则标头设置正确,但如果状态大于或等于 400,则标头被忽略。
gzip 模块也是如此。如果状态代码低于 500,gzip 模块会自动压缩响应正文。但是,如果 Apache 获取的 HTTP 状态代码大于或等于 500,则 gzip 模块将不执行任何操作。
我的 nginx 配置的一些相关部分:
proxy_intercept_errors off;
proxy_ignore_client_abort off;
proxy_http_version 1.1;
proxy_hide_header X-Powered-By;
proxy_set_header Connection ""; #for keepalive to backend
add_header X-Content-Type-Options nosniff;
### gzip ###
gzip on;
gzip_min_length 20; #default: 20
gzip_comp_level 9;
gzip_proxied any;
gzip_vary on;
gzip_types *;
gunzip on;
Run Code Online (Sandbox Code Playgroud)
我可以采取什么措施来停用此行为并将标头添加到 HTTP 错误响应甚至 gzip HTTP 500 响应中?
我需要解析 nginxaccess_log并将记录与用户帐户关联起来。为此,我决定使用自定义标头:
x-userid)$sent_http_x_useridmore_clear_headers 'x-userid'日志记录工作正常,我可以在 access_log 中看到正确的用户 ID。但是,如果我打开清除部分,access_log 将显示“-”而不是实际的用户 ID。
难道我做错了什么?是否可以在将其发送到客户端之前从应用程序记录标头,然后使用 nginx 将其清空?
有没有更好的方法来完成这项工作?该应用程序是PHP7,nginx是1.10.3
下面的屏幕截图是使用 firebug 制作的。单击登录按钮后,捕获的 firefox <-> Web 服务器通信发生。但是我在我的 Firefox 中看不到任何重定向。这是否意味着 Firefox 和 Web 服务器仅在 http 标头级别进行通信?
我在 ruby/mechanize 中准备了脚本来从论坛中抓取一些细节。我使用vBulletin.org论坛对其进行了测试/编码。然后我设法登录到我的测试论坛并愉快地使用正确的论坛来完成我的脚本。但我无法登录。我的脚本仅返回我认为“未成功登录尝试”的登录页面。
有人可能会向我解释下面的屏幕截图吗?
blindly/without thinking对 Web 服务器的回复。我对吗?当我单击登录按钮时,firefox 会在帖子中发送,auth_username=myusername&auth_password=mypassword&auth_login=Login但我的脚本发送auth_username=radek&auth_password=mypassword是可以的,还是&auth_login=Login必须显示该部分?
有没有机会在红宝石中模拟这种通信?
或者我在想是否可以record进行交流,然后replay在我的脚本中(如果可能)
登录页面的html
<form class="login" method="post"> <fieldset>
<legend>Members Login</legend>
<div>
<label for="auth_username">Username</label> <input id="auth_username" name="auth_username">
</div>
<div>
<label for="auth_password">Password</label> <input id="auth_password" name="auth_password" type="password">
</div>
</fieldset>
<div class="buttons">
<input name="auth_login" type="submit" value="Login"><p class="note"><a href="/forgotpassword">Forgot your password?</a></p>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我的红宝石脚本 …
我遇到了很少见的 503 错误,这些错误似乎难以确定。Varnishlog 快把我逼疯了,因为我似乎无法从中获得我想要的信息。
我希望看到 Varnish 所看到的客户端和后端通信。我认为记录在 Varnish 的默认错误页面上的 XID 号可以让我从日志缓冲区中过滤出确切的请求。但是,varnishlog 参数的组合没有给我我需要的输出。
以下仅显示客户端通信:
varnishlog -d -c -m ReqStart:1427305652
Run Code Online (Sandbox Code Playgroud)
虽然这仅显示了由此产生的后端通信:
varnishlog -d -b -m TxHeader:1427305652
Run Code Online (Sandbox Code Playgroud)
是否有单行显示整个请求?
在尝试设置 OpenDNS 并且未能使网站过滤真正起作用时,我意识到我的 ISP 正在对所有 HTTP 请求做一些邪恶的事情。长话短说,如果有Host:标题,我使用什么 IP 地址都没有关系,我得到的网站取决于Host:标题而不是其他任何东西。
即使我在请求中指定 HTTP/1.0,它似乎也会自动使用 HTTP/1.1。
例子:
google.com与Host: yahoo.com$ echo -e "HEAD / HTTP/1.0\r\nHost: yahoo.com\r\n\r\n" | nc google.com 80
HTTP/1.1 301 Moved Permanently
Date: Mon, 02 Jan 2012 10:50:13 GMT
Location: http://www.yahoo.com/
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
Cache-Control: private
Age: 0
Server: YTS/1.20.0
Connection: close
$
Run Code Online (Sandbox Code Playgroud)
Host: yahoo.com$ echo -e "HEAD / HTTP/1.0\r\nHost: yahoo.com\r\n\r\n" | nc 1.0.0.0 80
HTTP/1.1 301 Moved Permanently …Run Code Online (Sandbox Code Playgroud) 我正在使用 curl 请求使用以下Location:行重定向到不同 URL 的 URL :
Location:/path/to/resource#name
Run Code Online (Sandbox Code Playgroud)
据我了解,根据 HTTP 规范,重定向响应中的那一行是无效的,因此整个 curl 调用失败是可以理解的(在这种情况下,响应代码为 400)。但是,使用 wget 或 Web 浏览器请求 URL 会成功呈现页面(我假设通过在重定向之前填充绝对路径或删除锚标记的启发式方法)。
有什么我可以做的让 curl 做同样的事情(做成功跟随重定向所必需的事情,即使它是“正式”格式错误的)?
编辑:更多细节。最终的响应代码是 400(不是 404 或其他)。当我做一个HEAD请求(有curl -I -L),我得到一个302 Found(有Location: /Error)重定向到500 Server Error。但是,如果我执行常规请求(没有-I选项但有-L选项),我会得到http_code(在 curl 中--write-out)的400. 因此,在这种情况下,HEAD 请求的功能似乎与标准 GET 不同。
一些移动设备向我们的服务器发送以下不正确的请求:
GET / HTTP/1.0
Accept:
User-Agent : xxx
Run Code Online (Sandbox Code Playgroud)
空的 Accept 头会导致我们的 Ruby on Rails 服务器返回 500 错误。
在 Apache 中,以下指令允许我们在将标头发送到应用程序 RoR 服务器之前重写标头,以处理损坏的设备:
RequestHeader edit Accept ^$ "*/*" early
Run Code Online (Sandbox Code Playgroud)
我们目前正在设置 nginx,但事实证明,实现相同的解决方法很困难。我们能够设置:
proxy_set_header Accept */*;
Run Code Online (Sandbox Code Playgroud)
然而,这似乎必须无条件地完成。每当尝试做:
if ($http_accept !~ ".") {
proxy_set_header Accept */*;
}
Run Code Online (Sandbox Code Playgroud)
它抱怨消息:
"proxy_set_header" directive is not allowed here
Run Code Online (Sandbox Code Playgroud)
那么,使用 nginx,我们如何*/*在将请求发送到应用服务器之前将HTTP Accept 标头设置为空?
ELB 设置为接受公共 HTTPS (443) 连接并将它们作为 HTTP (80) 发送到 EC2 实例。
EC2 实例运行需要知道用户 IP 地址的 IIS 应用程序。根据我在本网站和其他地方读到的所有内容,ELB 应该将该信息存储在名为“X-Forwarded-For”的标头中。无论出于何种原因,ELB 似乎都没有将该特定标头传递给 IIS(或者 IIS 正在将其剥离?)。
知道我可能做错了什么吗?