- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为 nginx 1.4.1 使用以下配置:
server { listen 8000; server_name correct.name.gr; location /test/register { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1; }}
我想做的是,当用户访问 http://correct.name.gr:8000/test/register/
时,他们应该被代理到运行在端口 80 上的 apache。
当我访问 http://correct.name.gr:8000/test/register/
时,我得到了正确的结果 (index.php)。当我访问 http://correct.name.gr:8000/test/register/asd
时,我得到了正确的结果(来自 apache 的 404)。当我访问 http://correct.name.gr:8000/test/asd
时,我得到了正确的结果(来自 nginx 的 404)。当我访问 http://correct.name.gr:8000/test/register123
时,我得到了正确的结果(来自 apache 的 404)。
问题出在我访问 http://correct.name.gr:8000/test/register
时。我收到 301 响应,我被重定向到 http://localhost/test/register/
(注意尾部斜杠,当然还有“localhost”)!!!
我没有对 nginx 进行任何其他配置来放置尾部斜杠或类似的东西。你知道问题出在哪里吗?我希望 http://correct.name.gr:8000/test/register
通过代理到 apache 正常工作(或者如果不可能至少发出 404 错误而不是重定向到本地主机用户)。
更新 1:我在另一台计算机上尝试了 http://correct.name.gr:8000/test/register
昨天的行为.. 好吧,它奏效了:我刚刚收到一个 301 响应,将我指向正确的 http://correct.name.gr:8000/test/register/
!怎么可能在一台计算机上工作而不在另一台计算机上工作(我在两台计算机上使用相同的浏览器 Chrome)?明天我会再试一次,从第三方进行测试以查看行为。
谢谢!
最佳答案
我的猜测是您的上游服务器(apache 或您的脚本)触发了重定向到绝对 url http://localhost/test/register/
.因为你用 http://127.0.0.1
在你的proxy_pass
指令,nginx 找不到匹配的域名并返回 Location
header 原样。
我认为正确的解决方案是在重定向到内部 URL 时不使用绝对重定向。这始终是一个好习惯。
但是,在不更改上游服务器的情况下,有两个快速解决方案。
你可以使用
proxy_pass http://localhost;
这会告诉nginx upstream 的域名是localhost
.然后nginx就会知道替换http://localhost
通过 http://correct.name.gr:8000
当它在 Location
中找到该部分时来自上游的 header 。
另外一个是加一个proxy_redirect
强制 nginx 使用 http://localhost/
重写任何位置 header 的行
proxy_pass http://127.0.0.1;
proxy_redirect http://localhost/ /;
我更喜欢第一个解决方案,因为它更简单。使用 proxy_pass http://localhost;
没有 DNS 查找开销因为 nginx 在启动 web 服务器时会提前进行查找。
引用:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
关于http - nginx 和带有代理传递的尾部斜线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17422558/
我发现了一些令人费解的行为。给定一个包含 50 个日期的列表: structure(c("15513", "12830", "16503", "-3628", "15833", "13553", "4
我正在尝试创建单链表,但我不知道我做错了什么。 在插入元素 5、6、7、2、3、4 后,尾部应该是 4,但我得到的是 3,我不明白为什么。 这是我的代码: public void Insert(int
这是我的尾部代码(前 10 行): #include #include #include typedef char storage_datatype; #define MAXLINESIZE 1
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
是否有一种有效的方法可以从 List 中删除 X 元素的范围(例如尾部),例如LinkedList 在 Java 中? 显然可以一个一个地删除最后一个元素,这应该会导致 O(X) 级别的性能。至少对于
在之前的一篇文章我们介绍了《如何向php数组中头部和尾部添加元素》既然有添加元素,那么就有删除元素,今天这篇文章详细介绍如何删除数组中的头部元素和尾部元素,还有任意数组元素。 删除末尾元素:arr
在双向链表的实现中,我使用了典型的结构: struct node { void *data; struct node *prev; struct node *next; };
ECMA-335,III.2.4指定可以在递归函数中使用的tail.前缀。但是,我在C#和F#代码中都找不到它的用法。有使用in的示例吗? 最佳答案 您不会在当前的MS C#编译器生成的任何代码中找到
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
这个问题在这里已经有了答案: How to 'grep' a continuous stream? (13 个答案) 关闭 8 年前。 Tail 有以下选项: -f The -f opti
我试图弄清楚一旦我击中某个字符,如何从尾部修剪 Bash 中的字符串。 示例:如果我的字符串是这个(或任何链接):https://www.cnpp.usda.gov/Innovations/DataS
我试图弄清楚一旦我击中某个字符,如何从尾部修剪 Bash 中的字符串。 示例:如果我的字符串是这个(或任何链接):https://www.cnpp.usda.gov/Innovations/DataS
当我执行这段代码时,循环总是在第一次结束(即使 auth.log 的最后两行不包含“exit”),这意味着 $c总是得到一些字符串: while true; do c=$(tail -2 /v
我正在尝试编写一个“添加”函数,该函数接受节点中保存的值(表示为“n”),以及节点要添加到链表中的位置(表示为“pos”)。 我看到代码中有 3 个单独的添加函数 - addAtBeginning、a
为什么我不能得到“cd fjadf”? 程序总是向我显示 Bus error: 10... 我想用这个super_cut_tail()函数来截断用户指定的///fjdakf。但是为什么这个功能不能实现
有一个简化的表 mytable,其中列 ('id', 'mycolumn') 为 int 和 varchar(255 )分别。 在 mycolumn 中查找当前字符串具有最长公共(public)右侧部
这个问题已经有答案了: 已关闭13 年前。 Possible Duplicate: Get last n lines of a file with Python, similar to tail 你好
我想通过对写出的响应主体进行哈希处理来计算响应的实体标签。当我计算实体标签时,将实体标签添加到响应 header 已经太晚了。我想将实体标签添加到预告片中。我看到 net/http 包支持编写预告片,
我正在尝试通过 script.sh 从第 2 行到第 5 行打印文件 (myfile) 的内容。脚本无法从位置 2 打开文件。并且内容从第 1 行打印到第 4 行。以下是文件内容、命令和命令的输出。
在一个特殊的控制台上,我喜欢从/var/log/syslog 中过滤一些信息。这并不是很棘手: tail -f /var/log/syslog | awk '{print $2,$1,$9,$3,"\
我是一名优秀的程序员,十分优秀!