我定义了两个等价 nginx
指令,例如:
server {
listen 80;
server_name translations.example.com;
location / {
proxy_pass http://localhost:8080;
}
}
server {
listen 80;
server_name img.example.com;
location / {
proxy_pass http://localhost:9069;
}
}
但是,我发现第一个仅显示nginx欢迎页面(地址栏中有124.26.119.135
),而第二个按预期工作(img.example.com
并显示img-service)。
直接通过IP地址和端口访问服务对它们两者均有效(例如124.26.119.135:8080
和124.26.119.135:9069
)。
我看不出有什么区别吗?
nginx -t
不返回任何错误或警告:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
进一步的分析表明,似乎存在一个重定向循环,不断获取301 Permanently moved
,将translations.example.com
重定向到124.26.119.135
到124.26.119.135
等。
nginx
日志显示:
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.0" 301 185 "-" "SEO Consulting; Redirect Checker Tool V.02; IP:"
185.21.102.132 - - [16/Oct/2020:22:35:32 +0000] "GET / HTTP/1.1" 301 185 "" "SEO Consulting; Redirect Checker Tool V.02; IP:"
域似乎已正确配置:
host -t A translations.example.bot
产生translations.example.com has address 124.26.119.135
,对于img.example.com
:img.example.com has address 124.26.119.135
返回相同的结果。