简体   繁体   English

Nginx到iis转发错误400

[英]Nginx to iis forwarding Error 400

Please help me. 请帮我。 I have iis server and nginx proxy on it. 我有iis服务器和nginx代理。 When i connected to my nginx I get sometimes 400 Bad Request (Invalid hostname) error and when i press F5 and reload page my site loading correct (200 code) but without scripts\\css... and when I press F5 angain 400 error and so on. 当我连接到我的nginx时,我得到有时400错误请求(无效主机名)错误,当我按F5并重新加载页面我的网站加载正确(200代码)但没有脚本\\ css ...当我按F5 angain 400错误和等等。

iis on http://localhost:81 iis在http:// localhost:81上

I tried with two nginx configs: 我尝试了两个nginx配置:

First 第一

  location / {
            proxy_pass http://localhost:81;
            proxy_set_header    Host            $host;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-for $remote_addr;
            port_in_redirect off;
            proxy_connect_timeout 300;
        }

Second 第二

 location / {
            proxy_pass http://localhost:81;
            proxy_set_header Host $host;
            proxy_set_header X-Accel-Expires 0;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

Both first and second config have this error. 第一个和第二个配置都有此错误。 Nginx of 1.6.2 version. Nginx的1.6.2版本。

Nginx error.log is empty. Nginx error.log为空。 Nginx access log like this 像这样的Nginx访问日志

217.66.152.89 - - [16/Mar/2015:23:42:56 +0300] "GET / HTTP/1.1" 400 334 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"
217.66.152.89 - - [16/Mar/2015:23:42:58 +0300] "GET / HTTP/1.1" 200 689 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"
217.66.152.89 - - [16/Mar/2015:23:43:01 +0300] "GET / HTTP/1.1" 400 334 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"
217.66.152.89 - - [16/Mar/2015:23:43:03 +0300] "GET / HTTP/1.1" 200 689 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"

iis logs have only 200 and 304 codes iis日志只有200和304代码

Request headers 请求标头

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:mode=undefined; view=undefined
Host:(this is my host)
If-Modified-Since:Mon, 16 Mar 2015 12:56:48 GMT
If-None-Match:"4e905caae85fd01:0"
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36

I hope for your help. 我希望得到你的帮助。

Had the same issue. 有同样的问题。 It was caused by the fact that the server DNS name was resolving to an IPv4 address only, when "localhost" had both IPv4 and IPv6. 这是因为当“localhost”同时具有IPv4和IPv6时,服务器DNS名称仅解析为IPv4地址。

When NGINX tried to resolve an upstream " http://localhost " it was getting "::1" and switching to IPv6 - but HTTP.SYS (IIS network layer for the sake of discussion) later got an IPv4 address for the name specified in a "Host:" header. 当NGINX尝试解析上游“ http:// localhost ”时,它获得了“:: 1”并切换到IPv6 - 但HTTP.SYS(IIS网络层为了讨论)后来获得了指定名称的IPv4地址在“主机:”标题中。

This situation is not properly handled, despite the fact that the symbolic name, "localhost", IPv4 address and "::1" IPv6 one actually belong to the same machine. 尽管符号名称“localhost”,IPv4地址和“:: 1”IPv6实际上属于同一台机器,但这种情况没有得到妥善处理。

Workaround - remove proxy_set_header Host $host; 解决方法 - 删除proxy_set_header Host $host; directive or use numeric upstream address in proxy_pass URI. 指令或使用proxy_pass URI中的数字上游地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM