【发布时间】:2019-11-19 16:24:22
【问题描述】:
我有以下 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;
}
【问题讨论】:
标签: nginx nginx-location nginx-config