Nginx drops HTTPS from Akamai during rewrite

Akamai passes the HTTPS request to Nginx and Nginx drops HTTPS from the request as it performs a redirect. Here are the results from curl:

$ curl -v -L https://oursite.com/life/facts-and-arguments/ 2>&1 | egrep "^(<|>) (Host:|Location:|Server:|GET|HTTP)"
> GET /life/facts-and-arguments/ HTTP/1.1
> Host: oursite.com
< HTTP/1.1 301 Moved Permanently
< Server: openresty/1.13.6.1
< Location: http://oursite.com/life/first-person/ #Extra hop we're trying to avoid
> GET /life/first-person/ HTTP/1.1 
> Host: oursite.com
< HTTP/1.1 301 Moved Permanently
< Server: AkamaiGHost
< Location: https://oursite.com/life/first-person/
> GET /life/first-person/ HTTP/1.1
> Host: oursite.com
< HTTP/1.1 200 OK
< Server: openresty/1.13.6.1

Is there any way to have Nginx retain HTTPS while it performs a redirect so it doesn't go through this extra hop? I've tried configs similar to this: Thanks!

location ~ ^(?!(/a/|/b/|/c/))(([^.]*[^/]))$ {
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $host;
    set $redir_location $http_x_forwarded_proto://$host;
    rewrite ^(?!(/a/|/b/|/c/))(([^.]*[^/]))$ $redir_location$2/ permanent;
    }
1
задан 20 April 2018 в 23:50
1 ответ

Этот блок конфигурации nginx не соответствует вашему URL-адресу. [^ /] $ означает, что URL-адрес не должен заканчиваться косой чертой, в отличие от вашего. http: исходит из вашего конечного приложения, вероятно, не из nginx.

Примечание. Не перенаправляйте на $ http_x_forwarded_proto: // $ host , потому что вы не знаете, установлен ли $ http_x_forwarded_proto . Эта часть является ответственностью CDN, они должны редактировать HTTP 30x Location , который вы возвращаете. Просто сделайте это $ scheme: // $ host $ 2 .

1
ответ дан 3 December 2019 в 23:17

Теги

Похожие вопросы