Redirect ISPconfig portal 8080 page to https

Discussion in 'Installation/Configuration' started by Richard Bignell, Jan 18, 2019.

  1. Richard Bignell

    Richard Bignell New Member

    Hi,

    I can see this has been asked a lot before and i have tried many of the suggestions found but they all seem to relate to vhost websites rather than the main portal page.

    I have tried the following Rewrite commands in both .htaccess in the /var/www/ispconfig/ folder and within the apache2 vhost config file /etc/apache2/sites-available/ispconfig.vhost

    But when i visit http server.mydomain.co.uk:8080 i just get the bad request message and no redirect.

    Bad Request Your browser sent a request that this server could not understand.

    Code:
    Fri Jan 18 08:28:25 [email protected]:~] # cat /etc/apache2/sites-available/ispconfig.vhost
    ######################################################
    # This virtual host contains the configuration
    # for the ISPConfig controlpanel
    ######################################################
    
    Listen 8080
    NameVirtualHost *:8080
    
    <VirtualHost _default_:8080>
      ServerAdmin [email protected]
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://server.mydomain:8080
    I've tried {HTTPS} !on which makes no difference. I've also tried Rewrite outside the VirtualHost section but again no difference.

    In my access log i get this:

    Code:
    192.168.0.1 - - [18/Jan/2019:08:37:31 +0000] "GET / HTTP/1.0" 400 0 "-" "-"
    And in my error.log i get nothing.

    If i visit the ssl page directly it works fine but i get a 302 in the access log rather than a 400. 302 is funny because it suggests the redirect is working because its adding /login/ successfully but only when i've used https://

    Code:
    192.168.0.1 - - [18/Jan/2019:08:39:46 +0000] "GET / HTTP/1.1" 302 4366 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
    192.168.0.1 - - [18/Jan/2019:08:39:47 +0000] "GET /login/ HTTP/1.1" 200 3889 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
    192.168.0.1 - - [18/Jan/2019:08:39:48 +0000] "GET /themes/default/assets/stylesheets/pushy.min.css HTTP/1.1" 200 1177 "https://server.mydomain:8080/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    What you are trying to do can not work on non-standard ports like 8080. So there is no way to redirect a custom port like 8080 from http to https when someone uses http://someurl:8080 instead of https://someurl:8080 in his browser. An HTTP to HTTPS redirect works only for the standard port combination 80 + 443, so if you want to have such a redirect, then you will have to run ispconfig on port 443 instead of 8080 and modify it to be a name based vhost in case you run other websites on the same server and then you need another vhost on port 80 with the redirect code. When you search the forum for the topic to run ispconfig on port 443, then you should be able to find examples for that.
     
    Richard Bignell likes this.
  3. Richard Bignell

    Richard Bignell New Member

    PS

    I even tried (just as a test) adding the following to the index.php within /var/www/ispconfig but it seems if never reads index.php if https is not enabled, it just goes straight to the http error page.

    Code:
    // Check if https and redirect if not
    if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
                $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                    header('HTTP/1.1 301 Moved Permanently');
                    header('Location: ' . $redirect);
                        exit();
    }
     
  4. Richard Bignell

    Richard Bignell New Member

    Thank you for such a quick reply and explaining so clearly. It makes perfect sense now.
    I will try and convert to name based as you suggest similar to the alias that /phpmyadmin uses.
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    PHPMyAdmin works differently (it uses an Alias), so that's not a good basis in my opinion and won't work for ISPConfig.

    Basically all you have to do is to change port 8080 to 443 in the ispconfig vhost and add a ServerName line with the desired name like panel.yourdomain.tld or whatever subdomain you prefer. Then add another small vhost with the same servername and port 80 which contains the redirect code.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Correct, as this file does not get executed. the communication between browser and server gets stuck way before in establishing the connection, so no file from the vhost will get delivered and no redirect rules from vhost apply.
     

Share This Page