我有以下Nginx配置。我将所有HTTP请求重定向到HTTPS。我要实现的是,robots.txt(“ http://example.com/robots.txt”或“ 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;
}