Author Topic: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops  (Read 18712 times)

0 Members and 1 Guest are viewing this topic.

Offline
***
Whenever you are using [Nginx + Varnish + Apache] or [Nginx + Apache] you need to tell Apache that a SSL request is being served by a proxy server. So use the code below to force SSL .htaccess

Code: [Select]
SetEnvIf X-Forwarded-Proto "https" HTTPS=on
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IFModule>

Offline
*
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #1 on: September 27, 2018, 03:35:21 PM »
Hi.
Where i put this code?
With this code all domains redirect to https?

Offline
**
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #2 on: December 03, 2018, 03:59:41 PM »
Hi.
Where i put this code?
With this code all domains redirect to https?

.htaccess file.

Offline
**
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #3 on: December 03, 2018, 04:23:24 PM »
Whenever you are using [Nginx + Varnish + Apache] or [Nginx + Apache] you need to tell Apache that a SSL request is being served by a proxy server. So use the code below to force SSL .htaccess

Code: [Select]
SetEnvIf X-Forwarded-Proto "https" HTTPS=on
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IFModule>

This work great! Is possible to do this through vhost on the server side so we don't have to add this every time?

Offline
*
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #4 on: December 03, 2018, 09:49:38 PM »
I would suggest contacting cwp support to check it and they could integrate permanent solution if some issue exists.

main instructions
http://wiki.centos-webpanel.com/webservers-vhost-templates
http://wiki.centos-webpanel.com/webservers-update
http://forum.centos-webpanel.com/high-performance/wordpress-high-performance-instructions/
VPS & Dedicated server provider with included FREE Managed support for CWP.
http://www.studio4host.com/

*** Don't allow that your server or website is down, choose hosting provider with included expert managed support for your CWP.

Offline
**
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #5 on: December 04, 2018, 04:24:33 AM »
Thank for the idea. I've contacted them just now. Can you also do so too and anyone else? Hopefully they will see it's important. This cause redirect issues and app breaks because of the mixed content.

Offline
*
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #6 on: October 13, 2021, 06:01:31 PM »
Hello,

I know this issue, and i cant fix not yet but you can use temporary fix :

If you using only Apache, you can use this code for HTTPS redirecting in .htaccess file :

# Before evereything, redirect HTTPS
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTPS} !=on
   RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

   RewriteCond %{HTTP_HOST} !^www\.
   RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,E=HTTPS:1]
</IfModule>

If you using NGINX + APACHE with reverse proxy etc. you can use this code for HTTPS redirecting in .htaccess file :

# NGINX + APACHE Before evereything, redirect HTTPS
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{SERVER_PORT} 80
   RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

   # If you want www redirect..
   RewriteCond %{HTTP_HOST} !^www\.
   RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,E=HTTPS:1]
</IfModule>
---------------------------------------------------------------
T: +90 262 373 65 20
M: info@zirvesunucum.com
W: www.zirvesunucum.com
ZirveSunucum Information
---------------------------------------------------------------

Offline
**
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #7 on: October 14, 2021, 06:44:55 AM »
I don't know why you are using .htaccess for forcing https if you are using nginx.

Nginx is not working with .htaccess and so it is not taking all the code like if you are using apache alone.


To really force https instead of make a redirect, you better configure this in the webserver Main or Domain Config.

Select the user you wanna force, create a template and select "force-https" as nginx default vhost template.

This will do the real force of https instead of first use http and redirect a user to https and it is persistant for updates.


This is the way i use it and i never faced any problems with all my sites.

If you wanna force all users to only use HTTPS, configure this in the webservers main config.

Offline
*
Re: [Solution] Nginx + Varnish + Apache force SSL .htaccess Redirect Loops
« Reply #8 on: December 17, 2021, 09:47:52 PM »
I tried this solution:

SetEnvIf X-Forwarded-Proto "https" HTTPS=on
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IFModule>

But I have the same problem in some moments. it's extrange.

REgards.
https://alcazardesanjuan.com

-----------

Aśn le persiste el problema? me pasa lo mismo al utilizar nginx-varnish-apache, le siguió sucediendo o ya solucionó de otra manera?

Yo acabo de poner el codigo en el archivo htacess espero funcione.