nginx 顶级域重定向到子域
nginx top-domain redirects to subdomain
我的 nginx 配置将所有请求从 domain.ru 重定向到子域。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;
}
}
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/
因为您的 nginx 配置为 subdomain.domain.ru
。
对 domain.ru
的请求进入 subdomain.domain.ru
,其中肯定有足够的代码重定向到规范 URL,即 http://subdomain.domain.ru/
我的 nginx 配置将所有请求从 domain.ru 重定向到子域。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;
}
}
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/
因为您的 nginx 配置为 subdomain.domain.ru
。
对 domain.ru
的请求进入 subdomain.domain.ru
,其中肯定有足够的代码重定向到规范 URL,即 http://subdomain.domain.ru/