【发布时间】:2019-11-30 13:33:19
【问题描述】:
我已将 nginx 配置为跨我构建的 Web 应用程序的三个节点的前端负载平衡器。无论我在 upstream.server 和 server.server_name 中使用什么值,nginx 都会不断返回 400/bad request - invalid hostname 错误。我已经为这两个值尝试了 localhost 和 127.0.0.1 并使用匹配的 cURL/Postman 请求发出请求,但无济于事。
我还尝试设置 server.server_name 的值,包括端口号以更好地匹配传入的 HTTP HOST 标头,但无济于事。
nginx.conf
events {
worker_connections 1024;
}
http {
upstream myapp {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 8000;
server_name 127.0.0.1;
location / {
proxy_pass http://myapp;
}
}
}
cURL 请求会导致以下结果(使用 localhost 和 127.0.0.1 没有区别)。
C:\>curl -v http://127.0.0.1:8000/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Server: nginx/1.17.1
< Date: Mon, 22 Jul 2019 14:29:22 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/strict.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>
* Connection #0 to host 127.0.0.1 left intact
【问题讨论】:
-
有点相关:这个问题不是更适合serverfault.com吗?
-
公平,谢谢,张贴在那里。
标签: nginx