Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 09:51AM
Hi all.

I have nginx proxy for iis 7 server, but when I addressing to iis server I have a 400 Bad Request Invalid Hostname error periodically (when I press F5). So I saw the nginx and the iis logs and saw that my queries which have a 400 error code does not reach the IIS server.

I tried several configs:

location / {
proxy_set_header x-real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;

proxy_pass http://localhost:80;
}

....

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;
}
...

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;
}

Please help find the possible causes of this behavior
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 11:47AM
Try these settings;

keepalive_requests 500;
proxy_http_version 1.1;
proxy_ignore_client_abort on;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 02:09PM
Thank you a lot! But it is not worked for me. Also I tried to use this lines with previous configs and play with params.

My request header (just iis welcome.png)

Host: [my host here]
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Cache-Control: max-age=0
Referer: http://[my host here]/welcome.png
Cookie: mode=undefined; view=undefined
Connection: keep-alive
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 02:22PM
You would have to check the logs on both ends to see who is logging what, run some 'ab' or curl sessions.
And use the latest version of nginx.
Curl -i should tell you when a 4xx is returned who is returning it, then check its logfiles, enabling debug logging might show some more information.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 05:07PM
Thank you for your answers!
I installed the new version nigx and tried to set up logs. But I don't understand situation in general.
Is it IIS problem or nginx configuration problem ?


>>curl -i http://193.232.254.196:6058/
HTTP/1.1 400 Bad Request
Server: nginx/1.7.10
Date: Tue, 17 Mar 2015 20:06:51 GMT
Content-Type: text/html; charset=us-ascii
Content-Length: 334
Connection: keep-alive

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/str
ict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p>
</BODY></HTML>

debug.log
http://pastebin.com/6yBAABXF

IIS log is empty

Failed request tracing is enable for 399-500 codes and folder for it is empty too.

HTTPERR.log
2015-03-17 20:06:51 ::1%0 51176 ::1%0 8080 HTTP/1.1 GET / 400 - Hostname -

notice.log is empty

error.log is empty

info.log
2015/03/17 23:06:51 [info] 2136#3844: *3 client 217.66.152.25 closed keepalive connection

access.log
217.66.152.25 - - [17/Mar/2015:23:06:51 +0300] "GET / HTTP/1.1" 400 334 "-" "curl/7.33.0"


My full Nginx config http://pastebin.com/it3jGanp

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I trying to compare it with 200 code request


>>curl -i http://193.232.254.196:6
058/
HTTP/1.1 200 OK
Server: nginx/1.7.10
Date: Tue, 17 Mar 2015 19:44:40 GMT
Content-Type: text/html
Content-Length: 689
Connection: keep-alive
Last-Modified: Mon, 16 Mar 2015 12:56:48 GMT
Accept-Ranges: bytes
ETag: "4e905caae85fd01:0"
X-Powered-By: ASP.NET

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x
html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IIS7</title>
<style type="text/css">
<!--
body {
color:#000000;
background-color:#B3B3B3;
margin:0;
}

#container {
margin-left:auto;
margin-right:auto;
text-align:center;
}

a img {
border:none;
}

-->
</style>
</head>
<body>
<div id="container">
<a href="http://go.microsoft.com/fwlink/?linkid=66138&amp;clcid=0x409"><img src=
"welcome.png" alt="IIS7" width="571" height="411" /></a>
</div>
</body>
</html>

log fragments

notice.log is empty

error.log is empty

info.log
2015/03/17 22:44:40 [info] 4944#3408: *7 client 217.66.152.25 closed keepalive connection

access.log
217.66.152.25 - - [17/Mar/2015:22:44:40 +0300] "GET / HTTP/1.1" 200 689 "-" "curl/7.33.0"

debug.log
http://pastebin.com/4zY16wWf

IIS log
2015-03-17 19:44:40 127.0.0.1 GET / - 8080 - 127.0.0.1 curl/7.33.0 200 0 0 4
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 05:22PM
This suppose to go in the proxy_pass section;
keepalive_requests 500;
proxy_http_version 1.1;
proxy_ignore_client_abort on;


You trying to pass to:
proxy_pass http://localhost:8080

But are testing http://193.232.254.196:6 ???

There is no listen directive for port 6058 (http://193.232.254.196:6058/)

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 05:50PM
location / {

keepalive_requests 500;
proxy_http_version 1.1;
proxy_ignore_client_abort on;
...

It gives same situation.

http://193.232.254.196:6058/ is public ip that redirect to http:localhost:80 on remote server.

I suppose it, because

listen 6058;
server_name 193.232.254.196;

not work at all ( ERR_CONNECTION_REFUSED)

but with
listen 80
server_name localhost

I have access to my iis, but periodically there are 400 errors.

http://localhost:8080 is url for IIS on remote server.


For example to be clear I tested this configuration only on my remote server and also have 400 error periodically with testing http://127.0.0.1:81 on server.

listen 81;
server_name 127.0.0.1;


location / {

keepalive_requests 500;
proxy_http_version 1.1;
proxy_ignore_client_abort on;

proxy_set_header x-real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;

proxy_pass http://localhost:8080;


}
Re: Nginx to iis proxy, periodical Invalid hostname error
March 17, 2015 06:15PM
"HTTP Error 400. The request hostname is invalid."

I think this means your IIS server is not accepting localhost as requested name.

http://forums.iis.net/t/1168442.aspx?HTTP+Error+400+The+request+hostname+is+invalid

http://stackoverflow.com/questions/24243375/why-do-i-see-http-error-400-the-request-hostname-is-invalid-when-connected-t

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready