Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudFlare SSL and redirection on Apache+Nginx setup #1786

Closed
rallisf1 opened this issue Dec 17, 2017 · 10 comments
Closed

CloudFlare SSL and redirection on Apache+Nginx setup #1786

rallisf1 opened this issue Dec 17, 2017 · 10 comments

Comments

@rallisf1
Copy link

I am hosting a grav website at a Plesk shared hosting with Apache 2.2, PHP 7.1 and nginx as reverse proxy. It is a free hosting plan thus i get no SSL options for this. So i setup cloudflare for the domain and all hell broke loose.

Problem 1: Could not redirect to https

Force SSL option in the configuration would not work (both Chrome and Firefox return redirect error).

  • I tried entering the https base url in the Absolute url option and enabling it and then the routing broke, i could only browse the homepage. No other pages and no admin. Reverted changes by editing the yaml configuration.
  • I then tried an htaccess redirect which resulted in error 500 (no idea why, same redirect method works on any other setup i have come accross)
  • Last and successful was a PHP redirect directly injected in index.php, after the namespace declaration of course. (see https://stackoverflow.com/a/42141803/4035886 for the redirection code)

Problem 2: All the rendered links now included a :80 port in the url which made them useless

Read about a similar problem at #1690

Not completely familiar with grav source code but i got around this by editing /system/src/Grav/Common/Uri.php
i replaced
return ($this->scheme === 'http' && $this->port === 80) || ($this->scheme === 'https' && $this->port === 443);
with
return ($this->port === 80 || $this->port === 443);

I have posted my system info here: https://gist.github.com/rallisf1/95234ad819bc8cafa5b00deaa572ae98

I suppose everyone else with the same problem can use the workaround above until an official fix comes out.

Cheers.

@rhukster
Copy link
Member

Thanks for this detailed info. The SSL + Reverse Proxy is most definitely the cause. Weirdly we run getgrav.org with nginx reverse proxy to apache under SSL without issue. But I think this is because the SSL is at a higher cloudflare level.

@cord
Copy link

cord commented Jan 18, 2018

Am using cloudlflare ssl as well, but not sure if it is purely related to this setup.
Since updating v1.2.2 to v1.3.10 I have a similar situation where in a custom plugin (redirect to remove an affiliate get parameter from the url)

$uri = new Uri();
$base_url = $uri->base() . $uri->url();

header("Location: $base_url", true, '303');

returns http even the page was called as https.

the config setting force_ssl seems not be be applied in ->base().

my workaround:

if ($this->config->get('system.force_ssl')) {
   $base_url = str_replace('http://', 'https://', $base_url)
}

@Blazeflack
Copy link

I used the workaround from @rallisf1 to fix the issue described in #1690. It worked for me as well.

@jeremycherfas
Copy link

I had the same problem, arose recently, cannot be sure when. The fix from @rallisf1 Worked for me, I think. Not yet tested extensively.

@jeremycherfas
Copy link

This is still an issue after the latest upgrade. I applied the fix again and everything seems to work again.

@jeremycherfas
Copy link

I hope this will be fixed in 1.6

@rhukster
Copy link
Member

Fixed in 1.6

@jeremycherfas
Copy link

Any idea when 1.6 will be out of beta? This bug catches me out every time I update 1.5. Thanks

@rhukster
Copy link
Member

rhukster commented Jan 8, 2019

Soonish!.. was hoping to have it out in December, but got caught out by holidays...

@jeremycherfas
Copy link

Cool. Thanks. I can wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants