Dockerized WHMCS w/ NGINX Reverse Proxy

SagnikSSagnikS Hosting ProviderOG

Hello!

I have been thinking of dockerizing my WHMCS setup recently, so I grabbed a dev license and tried setting everything up. The frontend is loading fine, but I'm getting a too many redirects error when trying to access the admin panel. Here's the docker compose file

This is the location block that handles the proxying

 location / {
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Connection "";
    proxy_pass http://whmcs-prod/;

 }

Any help would be appreciated :sweat_smile:

Comments

  • You should remove the trailing slash from the proxy pass directive and add the "host" header. Also, proxy redirect should be set to off and a few other minor things.

    Try something like this:

    proxy_pass         http://localhost:3000;
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    
    Thanked by (1)SagnikS
  • SagnikSSagnikS Hosting ProviderOG

    @Solaire said:
    You should remove the trailing slash from the proxy pass directive and add the "host" header. Also, proxy redirect should be set to off and a few other minor things.

    Try something like this:

    proxy_pass         http://localhost:3000;
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    

    Changed it to this, but no luck.

      location / {
        proxy_http_version 1.1;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
        proxy_redirect     off;
        proxy_pass http://127.0.0.1:4222;
    
     }
    

    If it may be of interest, this is the cURL output:

     sagnik@SagnikS-WS  ~  curl -I https://whmcs.test/admin/login.php
    HTTP/2 302 
    server: nginx
    date: Sat, 18 Jan 2020 08:49:23 GMT
    content-type: text/html; charset=utf-8
    location: https://whmcs.test/admin/login.php
    x-powered-by: PHP/7.3.13
    set-cookie: <WHMCScookie>; path=/; secure; HttpOnly
    expires: Thu, 19 Nov 1981 08:52:00 GMT
    cache-control: no-store, no-cache, must-revalidate
    pragma: no-cache
    
  • SagnikSSagnikS Hosting ProviderOG

    The only workaround I've found till now was to set the WHMCS system URL to an http URL. :confused:

  • SolaireSolaire OG
    edited January 2020

    @SagnikS said:
    The only workaround I've found till now was to set the WHMCS system URL to an http URL. :confused:

    The first question that popped to mind was actually if whcms is configured to enforce HTTPS but I didn't ask that for no particular reason. :tongue:

    Since you're using http in your nginx config WHCMS will continously send your browser an http 302, which will change nothing since nginx will still perform a http request (nginx won't respond to the whcms request but rather relay it to your browser). Hence the permant redirect.

    Since you're using a reverse proxy you're basically making two requests, one to nginx and then nginx makes one to whcms. The last request is perfectly fine to be http but then you'd probably run into other issues (since whcms thinks it runs on http it might not load images over https for example). The simplest solution would be to change the nginx config to connect over https, but adding something like proxy_set_header X-Forwarded-Proto https; might also work if that is supported by WHCMS.

    Sorry for the short replies, feel free to ask for more details. Just having a fight with my phones keyboard atm..

    Thanked by (1)SagnikS
  • SagnikSSagnikS Hosting ProviderOG

    @Solaire said:

    @SagnikS said:
    The only workaround I've found till now was to set the WHMCS system URL to an http URL. :confused:

    The first question that popped to mind was actually if whcms is configured to enforce HTTPS but I didn't ask that for no particular reason. :tongue:

    Since you're using http in your nginx config WHCMS will continously send your browser an http 302, which will change nothing since nginx will still perform a http request (nginx won't respond to the whcms request but rather relay it to your browser). Hence the permant redirect.

    Since you're using a reverse proxy you're basically making two requests, one to nginx and then nginx makes one to whcms. The last request is perfectly fine to be http but then you'd probably run into other issues (since whcms thinks it runs on http it might not load images over https for example). The simplest solution would be to change the nginx config to connect over https, but adding something like proxy_set_header X-Forwarded-Proto https; might also work if that is supported by WHCMS.

    Thanks a ton, I'll give that a go after WHMCS reissues my Dev license.

    @Solaire said: Sorry for the short replies, feel free to ask for more details. Just having a fight with my phones keyboard atm..

    No problem mate, I greatly appreciate your help. I was stuck on a dead end on this, you've helped me out a lot :smiley:

    Thanked by (1)Solaire
Sign In or Register to comment.

This Site is currently in maintenance mode.
Please check back here later.

→ Site Settings