<div dir="ltr">Hi,<div><br></div><div>We have a setup with tomcat/apache and nginx.</div><div><br></div><div>When a redirect occurs from the application from https to http, the nginx gets trapped in a redirect loop.</div><div>
<br></div><div>In the apache configuration we have this setting:</div><div><br></div><div><div><IfModule mod_expires.c></div><div>ExpiresActive On</div><div>ExpiresDefault "access plus 1 month"</div><div>ExpiresByType image/gif "access plus 1 year"</div>
<div>ExpiresByType image/jpeg "access plus 1 year"</div><div>ExpiresByType image/png "access plus 1 year"</div></div><div>.... more mimetypes</div><div><br></div><div>The nginx configuration has this location</div>
<div><br></div><div><div> location / {<br></div><div> proxy_pass <a href="http://def-t-site1/">http://def-t-site1/</a>;</div><div> proxy_http_version 1.1;</div><div> proxy_hide_header Expires;<br></div>
<div> proxy_hide_header Last-Modified;</div><div> proxy_redirect off;</div><div> proxy_set_header Host $http_host;</div><div> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</div><div>
<br></div><div> proxy_cache http_def;</div><div> proxy_cache_key $scheme://$host$uri$is_args$args;</div><div> # proxy_cache_key "$scheme://$host$request_uri";</div><div> proxy_cache_valid 200 302 10m;</div>
<div> proxy_cache_valid 404 1m;</div><div> add_header Cache-Control "public";</div><div> add_header X-Cache-Status $upstream_cache_status;</div><div> add_header X-Via $hostname;</div>
<div> }<br></div><div><br></div><div>a similar setting we have for 443 port (https). </div><div><br></div><div>If we remove ExpiresDefault "access plus 1 month" from apache, the redirect loop does not occur. The cache of nginx uses a TTL of 1 month after the redirect occurs. This causes a redirect loop, since the https request is cached as well.</div>
<div><br></div><div><br></div><div>So far, we tried several things</div><div>- proxy_cache_valid 200 301 0m; </div><div>No change in the TTL. The redirect loop is not solved, and the TTL is still a month. </div></div><div>
<br></div><div>Then we tried to configure the expire headers in nginx. That solves the redirect, but unfortunately</div><div>the expire headers are not set. We tried for instance:</div><div><br></div><div><div>if ($upstream_http_content_type ~ "image/jpeg") {</div>
<div> <span class="" style="white-space:pre"> </span> expires 2m;</div><div>}</div><div><br></div><div>or </div><div>map $upstream_http_content_type $new_cache_control_header_val {</div><div> default $upstream_http_cache_control;</div>
<div> "~*image/jpeg" "max-age=120, must-revalidate";</div><div>}</div></div><div><br></div><div>but these settings did not have any effect on the TTL of the images.</div><div><br></div><div>So, is there a way to avoid the redirect loop and set the expire header per mimetype in nginx ?</div>
<div><br></div><div>Thanks!</div><div><br></div><div><br clear="all"><div><br></div>-- <br>Martijn Gijsberti Hodenpijl<br>Web Developer Hippo
</div></div>