Sponsor:

Server and Web Integrator
Link:
Kloxo-MR logo
6.5.0 or 7.0.0
Click for "How to install"
Donation/Sponsorship:
Kloxo-MR is open-source.
Donate and or Sponsorship always welcome.
Click to:
Click Here
Please login or register. 2017-05-28, 02:46:26

Author Topic: PHP force redirect SSL NginxProxy endless loop  (Read 4703 times)

0 Members and 1 Guest are viewing this topic.

Offline chrisf

  • Senior Master
  • **
  • Posts: 883
  • Karma: +11/-1
  • Gender: Male
  • Be the change that you wish to see in the world.
    • View Profile
    • Conviction's Hosting
PHP force redirect SSL NginxProxy endless loop
« on: 2013-10-05, 09:32:39 »
I switched to nginxproxy from apache to benefit from the speed on my shared hosting production server.

I have a few domains with SSL enabled and suddenly the sites were in a endless loop and they would not display.

I traced the problem to php checking $_SERVER['HTTPS'] - which behind nginx proxy apache does not know it is https being served.

I was pulling my hair out trying to get this to work - but php was getting environment and server variables from apache which doesn't know nginx is sending ssl pages.

The fix is simple! YET I hope I save someone the trouble I had with this.

ssh:
/home/nginx/conf/globals
if you are using a custom.proxy.conf just add the below lines, if not we must create it:
cp proxy.conf custom.proxy.conf

vim custom.proxy.conf

Find all the lines where it says proxy_set_header and add this line:

Code: [Select]
proxy_set_header X-Forwarded-Protocol $scheme;

Then go to the directory of the website having the endless ssl loop due to a php redirect.
Example:
Code: [Select]
if ($_SERVER['HTTPS'] !== on) {
// redirect to https here ----

Add this to the .htaccess of the domain with ssl:
Code: [Select]
SetEnvIf X-Forwarded-Protocol https HTTPS=on

sh /script/fixweb
sh /script/restart-all

All fixed :)

This is for those who understand php programming and ssl redirect being forced through php headers.

Everyone else :)  this doesn't apply....

Enjoy
« Last Edit: 1970-01-01, 01:00:00 by Guest »
Christopher

Knowledge in: PHP, Perl, MySQL, Javascript, Actionscript, FLASH, HTML, CSS
Server Administrator / Developer: https://convictionshosting.com

Offline fossxplorer

  • Master
  • **
  • Posts: 602
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #1 on: 2014-04-27, 00:35:30 »
Why the heck didn't i find this post that would have saved me 1 night sleep and almost 24h of research and troubleshooting?
I'm convinced your findings here will help MANY users of Kloxo-MR. 

EDIT: can you update the typo as it should be: SetEnvIf X-Forwarded-Proto https HTTPS=on
and you if you are using Hiawatha proxy, you don't need fixweb/restart-all as it's already sending  X-Forwarded-Proto to the backend.
« Last Edit: 2014-04-27, 01:04:56 by Mella »
Kloxo-MR!

Offline chrisf

  • Senior Master
  • **
  • Posts: 883
  • Karma: +11/-1
  • Gender: Male
  • Be the change that you wish to see in the world.
    • View Profile
    • Conviction's Hosting
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #2 on: 2014-04-27, 01:18:14 »
Not a typo :) as in nginx configuration I had added the full 'protocol' - however if Hiawatha is sending proto to the backend, simply change that (as you have).

Christopher

Knowledge in: PHP, Perl, MySQL, Javascript, Actionscript, FLASH, HTML, CSS
Server Administrator / Developer: https://convictionshosting.com

Offline quacos

  • Junior Member
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #3 on: 2014-06-19, 18:32:59 »
chrisf, thank you for this saving time tip!

Offline cmdman

  • Senior Member
  • *
  • Posts: 284
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #4 on: 2014-06-26, 13:58:42 »
@chrisf
can you explain me bit more i have same issues but i didnt get your fix can yu more specific guide me

Offline chrisf

  • Senior Master
  • **
  • Posts: 883
  • Karma: +11/-1
  • Gender: Male
  • Be the change that you wish to see in the world.
    • View Profile
    • Conviction's Hosting
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #5 on: 2014-06-27, 22:49:39 »
That was step by step.  If you need more help (send me a PM) and we'll see what we can do :)
Christopher

Knowledge in: PHP, Perl, MySQL, Javascript, Actionscript, FLASH, HTML, CSS
Server Administrator / Developer: https://convictionshosting.com

Offline letux

  • Valuable Member
  • *
  • Posts: 129
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #6 on: 2016-11-10, 23:13:27 »
can't fiend " /home/nginx/conf/globals " !!

Online MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 14,490
  • Karma: +105/-8
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #7 on: 2016-11-11, 07:28:57 »
can't fiend " /home/nginx/conf/globals " !!
If using Kloxo-MR 7.0, go to '/opt/configs/nginx/conf/globals' instead '/home/nginx/conf/globals'
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline letux

  • Valuable Member
  • *
  • Posts: 129
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #8 on: 2016-11-11, 10:43:41 »
and sorry i didn't fiend 'proxy.conf'
but i fiend more than file,
- proxy_standard.conf
- proxy_standard_ssl.conf
- proxy_wildcards.conf
- proxy_wildcards_ssl.conf
which file i copy and edit it ?

Online MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 14,490
  • Karma: +105/-8
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #9 on: 2016-11-11, 14:38:19 »
All.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline intan

  • Junior Member
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #10 on: 2016-11-23, 22:34:33 »
mengapa nginx 502 badgateway add domain di client ?

Online MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 14,490
  • Karma: +105/-8
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #11 on: 2016-11-24, 00:37:34 »
mengapa nginx 502 badgateway add domain di client ?
Bisa lebih diperjelas?.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline intan

  • Junior Member
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #12 on: 2016-11-24, 11:06:39 »
Jdi pd saat membuat website baru pada client setelah pilih adddomain kemudian menghapus file image dan index.html kemudian download wordpress setelah itu ekstrak. ketika dibuka dibrowser muncul erorr 502 badgateway jika menggunakan nginx. lain jika menggunakan hiawatha,apache,httpd berhasil masuk ke setup wordpress pd saat buka browser dan msuk ke domain tersebt.

Online MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 14,490
  • Karma: +105/-8
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #13 on: 2016-11-24, 11:20:59 »
Sementara pakai apache atau hiawatha-proxy saja.

Saya menemukan 'banyak' keanehan pada nginx untuk versi akhir-akhir ini.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline intan

  • Junior Member
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: PHP force redirect SSL NginxProxy endless loop
« Reply #14 on: 2016-11-24, 11:24:57 »
baik, Mas Mustafa Ramadhan trimakasih saranya... :) :D

 


MRatWork Affiliates:    BIGRAF(R) Inc.    House of LMAR    EFARgrafix
Click Here

Page created in 0.058 seconds with 19 queries.

web stats analysis