gpt4 book ai didi

internet-explorer - Nginx:返回错误 403 并显示一条消息

转载 作者:行者123 更新时间:2023-12-03 23:40:07 24 4
gpt4 key购买 nike

如果用户代理是 MSIE 6 并显示自定义错误消息,我希望 nginx 返回错误 403。
我使用了这段代码,一切都在第一分钟内奏效。然后它只是返回了没有消息的错误!不知道为什么...
这是代码(我试图用 ' 而不是 ",来获得没有 ' 或 "的纯文本,但仍然没有运气):

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
if ($http_user_agent ~ "MSIE 6" ) {
return 403 "Browser not supported. Please update or change to another one.";
}
}

编辑:忘了说它在 php 块中,因为我只想为 PHP 请求阻止 MSIE 6。

最佳答案

实际上,您的配置应该可以工作。您可以使用 curl 来检查它:

# curl -i -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1" http://localhost/i.php
HTTP/1.1 403 Forbidden
Server: nginx/1.3.6
Date: Wed, 26 Dec 2012 10:05:34 GMT
Content-Type: application/octet-stream
Content-Length: 62
Connection: keep-alive

Browser not supported. Please update or change to another one.

访问日志也值得检查(默认情况下 log_format 包含 $http_user_agent 变量)。

顺便说一下,/etc/nginx/fastcgi.conf 中有什么?

另一件事是,如果您希望使用真正的 MSIE 6 浏览器的人看到您的消息,您最好这样做:
location ~ \.php$ {
...
if ($http_user_agent ~ "MSIE 6" ) {
return 403;
}
error_page 403 /old_browser.html;
}

并使用您的消息创建 old_browser.html。请注意,此文件应大于 512 字节,以确保 MSIE 将显示其内容而不是一些标准的 IE 403 消息。类似工具 http://browsershots.org非常适合调试此类情况。 :)

关于internet-explorer - Nginx:返回错误 403 并显示一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com