我的nginx配置将所有请求从domain.ru重定向到subdomain.domain.ru,我不明白为什么。这是我的配置:
upstream upstream_server {
server unix:/sockets/inst_site.sock fail_timeout=60s;
}
server {
listen 8000;
server_name www.subdomain.domain.ru;
return 301 $scheme://subdomain.domain.ru$request_uri;
}
server {
listen 8000;
server_name subdomain.domain.ru;
#index index.html;
location /static/ {
autoindex off;
root "/project/inst_site/";
if (!-e /project/inst_site$uri) {
rewrite ^/static(.*)$ /static-root$1;
}
}
location /static-root/ {
autoindex off;
root "/project/inst_site/";
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
location /graphql/ {
proxy_set_header Host localhost;
proxy_pass http://upstream_server;
}
location /admin/ {
proxy_set_header Host localhost;
proxy_pass http://upstream_server;
}
autoindex off;
root "/project/inst-ng/dist/inst-ng";
try_files $uri $uri/ index.html;
}
}
Nginx运行在一个将端口80暴露于端口8000的容器中。没有提及“ domain.ru”,为什么它仍然可以提供服务?
已添加: 实际上,它会响应具有永久重定向的任何子域:
curl --head http://nhnhnhnhnh.domain.ru
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.8
Date: Thu, 21 Feb 2019 21:37:57 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://subdomain.domain.ru/
答案 0 :(得分:1)
因为您的nginx已配置为subdomain.domain.ru
。
对domain.ru
的请求进入subdomain.domain.ru
,这肯定有足够的代码重定向到http://subdomain.domain.ru/的规范URL