I'm trying to run a mixed SSL / non-SSL site on Aegir with Nginx but running into issues (redirection loops). I think I've narrowed down the problem code in the nginx config but I'm not familiar enough with nginx to be able to fix it.
I've enabled nginx_ssl in aegir and have my certificates installed. Everything works properly if I browser https pages. The issue comes in in that anonymous users only use https pages if they're on /user*, /cart, or /checkout*. When the anonymous user is redirected from http://website.com/user/login to https://website.com/user/login a redirect loop is triggered. If they go straight to https://website.com/user/login, no redirect loop. Interestingly the /cart and /checkout URLs work seamlessly.
I'm using the secure pages module for this, but I've also tried context_ssl with the same results. After a bit of investigation it looks like the problem comes down to this code in config/includes/nginx_simple_include.conf:
location @drupal {
error_page 418 = @nobots;
if ($args) {
return 418;
}
rewrite ^/(.*)$ /index.php?q=$1 last;
}
The rewrite here seems to be triggering a loop. However, cart and checkout pages are exceptions handled differently due to cookies in another part of the file:
location ~* ^/(?:.*/)?(?:user|cart|checkout|logout|flag) {
if ($is_bot) {
return 403;
}
access_log off;
set $nocache_details "Skip";
try_files $uri @drupal;
}
If I make encryption required on the site in aegir, all of the redirection happens properly, and I'm guessing that's thanks to the different configuration of the non-ssl vhost.
Any help on what I can do to stop the redirect loop? Can I simply alter the rewrite line somehow, or am I totally off on the wrong tangent?
Thanks!
Scott
Comments
Comment #1
omega8cc commentedThis config doesn't exist in the vanilla Aegir. It look like you are running BOA? Then you should read the how-to: http://drupalcode.org/project/barracuda.git/blob/HEAD:/docs/SSL.txt and generally search the issue queue before posting duplicate issues.
Comment #2
omega8cc commentedA hint: redirect loop can be caused by the standard global SSL proxy provided by BOA. BOA is not designed to support Aegir SSL feature (at least not yet). Read the SSL how-to.
Comment #3
hadsie commentedI'm not using Barracuda / BOA, just stock Aegir. The config file is also located in provision at provision/http/nginx/nginx_simple_include.conf (http://drupalcode.org/project/provision.git/blob/HEAD:/http/nginx/nginx_...) so it seems like this is part of vanilla Aegir unless I'm missing something?
I've also tried the SSL.txt that you mentioned but with no change. Where do I find the SSL how to that you mentioned?
Comment #4
omega8cc commentedAh, I assumed you are using BOA because you have submitted this issue first in the BOA old queue on GitHub. Sounds like a bug then!
Just to confirm, which Aegir version are you using? I assume 1.x, because in the 2.x we don't have nginx_simple_include.conf any longer.
Comment #5
hadsie commentedYa, I posted there because I really had no idea where else to, and nginx for drupal seemed perfect :).
I'm running version 1.10. But perhaps it would make more sense to upgrade to 2.x dev branch rather than looking into this further?
Comment #6
omega8cc commentedThis should be fixed in 1.x and 2.x since we have the same config also in the extended (default) Nginx config in 2.x
However, I'm not sure if this is what causes the problem, so this needs further investigation.
Comment #7
anarcat commentedso yeah, @hadsie, let's try to reproduce this in 2.x shall we? :)
Comment #8
hadsie commentedCool, just working on the upgrade now - had to wait till the weekend when traffic is down on the site :). Also decided to take a step back and learn a bit more about nginx configuration.
Comment #9
hadsie commentedOk, so I'm able to reproduce the redirect loop in 2.x. Same symptoms as before.
Comment #10
hadsie commentedComment #11
omega8cc commentedWhat is your browser identity? These two locations are designed to prevent known bots and crawlers from indexing never ending sub-pages, like generated by calendars and exposed views. These locations don't cause any loop, just permanent redirect to $args-free URL, if bot/crawler is discovered:
It also honors URL scheme, as you can see.
I would suggest to test this more, looking at HTTP headers with
curl -I urlto find what exactly happens and where. It could be also somewhere in the code, module used, its configuration etc. At least, I don't see any reason in the Nginx config to cause redirect loop.Comment #12
omega8cc commentedAlso, take a look at how we suggest to do it in BOA, in the local.settings.php directly: http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/overri...
And if you are using a module for this, I hope you have applied required patches to Drupal core, as we do it in our enhanced D7 core: https://omega8.cc/how-to-add-custom-platform-properly-140 and https://github.com/omega8cc/7x/tree/7.23.1
Comment #13
hadsie commentedI've tried in Chrome, Safari, and Firefox all with the same results.
Curl -I shows the following:
So it doesn't appear to be looping with curl for some reason? I've tried to pull aegir out of the equation and installed @perusio's nginx configuration files found here https://github.com/perusio/drupal-with-nginx. With these installed I'm able to use SSL w/ securepages and don't hit any redirect loops.
And if you are using a module for this, I hope you have applied required patches to Drupal coreSorry, I'm not sure what you mean. If I'm using a module for what? I'm also not sure which required patches you're referring to. I have applied the ones that the securepages module suggests.
Either way, I've got a working configuration now, which is a good start, so now I just have to track down the code that's causing the loop. Thanks for all your help!
Comment #14
anarcat commentedcan we get a diff with the regular config files?
Comment #15
hadsie commentedI don't think this will be possible as the perusio config is split up into a bunch of different files and I'm not sure I understand fully the meaning or how they work together just yet. Even if I were able to simplify it into a single file, the two would likely be so different that a diff wouldn't be useful. Though simplifying it may help me get to the bottom of this too.
For now, I've just made SSL a requirement rather than having SSL/Non-SSL pages.
Comment #16
omega8cc commented@hadsie
I would take a look at the vhost sections/rewrites instead of locations/rules in the included config.
The SSL feature and corresponding logic responsible for SSL enabled vhost generation has been modified during SSL refactoring, and I never tested it after these changes. It is still possible it never worked under some never tested conditions, and that those modifications had no impact, but I just want to point out that we (at Omega8.cc and more generally, in BOA) never experienced issues like this, but we also never used Aegir built-in SSL feature, just SSL proxy and otherwise standard includes, so maybe there is a culprit hidden we haven't discovered yet.
Comment #17
ergonlogicPlease confirm whether this is still an issue in Aegir 2.0+.
Comment #18
helmo commentedThe 6.x-2.x branch will go EOL along with Drupal this week. So I'm closing
this issue. If it remains a confirmed issue in 7.x-3.x, feel free to re-open,
or better yet, create a new issue referencing this one.
Comment #19
millenniumtreeI've found that this happens in Aegir 3.5 and 3.6 as well.
Create an aegir site with SSL enabled (not required).
Don't redirect to a specific domain (www or otherwise - may still break with redir, but trying to keep things simple)
Enable securepages with the following options:
"Switch back to http pages when there are no matches" checked.
Set your non-secure and secure base URLs:
http://DOMAIN.COM
https://DOMAIN.COM
Set your secure URLs with either option "secure all except" or "secure only...".
Now load a page and click a link that would take you to the "other side" (secure if on an insecure page, insecure if on a secure page).
You should get a redirect loop. Hard-refresh should then load properly.
What's happening is that nginx is caching the 302 redirect and serving it repeatedly.
I found a solution!
In /var/aegir/config/includes/nginx_vhost_common.conf:
In the "location = /index.php" block, change this:
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
to
fastcgi_cache_key "$scheme$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$sent_http_x_local_proto$cookie_respimg";
Adding the $scheme to the fastcgi_cache_key prevents the 302 from being cached for secure and re-served on insecure or vice-versa.
Edit: I apologize - upon further review of the original post - mine is an entirely different problem... But it is still a redirect loop related to nginx and securepages.
Comment #20
millenniumtreeComment #21
memtkmcc commented@millenniumtree -- Please open new issue. Thanks.
Comment #22
memtkmcc commentedI have opened new issue #2768869: Nginx fastcgi_cache_valid TTL logic is incorrect