Robots.txt 不应重定向到 HTTPS
Robots.txt should not be redirected to HTTPS
我有以下 Nginx 配置。我将所有 HTTP 请求重定向到 HTTPS。我想要实现的是 robots.txt ("http://example.com/robots.txt" or "http://example2.com/robots.txt") 上的 HTTP 请求不会被重定向到 HTTPS。我很难找到合适的陈述。
我的 Nginx 配置
server {
server_name example.com www.example.com example2.com www.example2.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-HTTPS-Protocol $ssl_protocol;
proxy_set_header X-NginX-Proxy true;
location / {
proxy_pass http://127.0.0.1:9092;
}
listen 443 ssl;
ssl_certificate /path
ssl_certificate_key /path
include /path
ssl_dhparam /path
}
server {
server_name example.com www.example.com example2.com www.example2.com;
listen 80;
listen [::]:80;
#
# What to put here not to redirect robots.txt to HTTPS?
#
if ($host = www.example.com) {
return 301 https://$host$request_uri;
}
if ($host = example.com) {
return 301 https://$host$request_uri;
}
if ($host = www.example2.com) {
return 301 https://$host$request_uri;
}
if ($host = example2.com) {
return 301 https://$host$request_uri;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-HTTPS-Protocol $ssl_protocol;
proxy_set_header X-NginX-Proxy true;
location / {
proxy_pass http://127.0.0.1:9092;
}
return 404;
}
简单的答案是废弃第二个 server
块并重新开始。也许是这样的:
server {
server_name example.com www.example.com example2.com www.example2.com;
listen 80;
listen [::]:80;
location / {
return 301 https://$host$request_uri;
}
location = /robots.txt {
root /path/to/directory;
}
}
我有以下 Nginx 配置。我将所有 HTTP 请求重定向到 HTTPS。我想要实现的是 robots.txt ("http://example.com/robots.txt" or "http://example2.com/robots.txt") 上的 HTTP 请求不会被重定向到 HTTPS。我很难找到合适的陈述。
我的 Nginx 配置
server {
server_name example.com www.example.com example2.com www.example2.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-HTTPS-Protocol $ssl_protocol;
proxy_set_header X-NginX-Proxy true;
location / {
proxy_pass http://127.0.0.1:9092;
}
listen 443 ssl;
ssl_certificate /path
ssl_certificate_key /path
include /path
ssl_dhparam /path
}
server {
server_name example.com www.example.com example2.com www.example2.com;
listen 80;
listen [::]:80;
#
# What to put here not to redirect robots.txt to HTTPS?
#
if ($host = www.example.com) {
return 301 https://$host$request_uri;
}
if ($host = example.com) {
return 301 https://$host$request_uri;
}
if ($host = www.example2.com) {
return 301 https://$host$request_uri;
}
if ($host = example2.com) {
return 301 https://$host$request_uri;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-HTTPS-Protocol $ssl_protocol;
proxy_set_header X-NginX-Proxy true;
location / {
proxy_pass http://127.0.0.1:9092;
}
return 404;
}
简单的答案是废弃第二个 server
块并重新开始。也许是这样的:
server {
server_name example.com www.example.com example2.com www.example2.com;
listen 80;
listen [::]:80;
location / {
return 301 https://$host$request_uri;
}
location = /robots.txt {
root /path/to/directory;
}
}