Connecting Though a Reverse Proxy to ossn server.

Donald Wood Posted in Technical Support 5 years ago

I'm still looking for help with getting ossn working behind a nginx reverse proxy. I have one ip with many servers behind the reverse proxy. I can get the ssl certs to load on the reverse proxy machine for the ossn site. But the site shows no css and you can't login. Sense all traffic goes through the reverse proxy I can't put the ssl cert on the ossn server. Has anyone had simular setups? If so any ideas or suggestions? I have tried to modify the ossn.config file and used the https:example.com but I still could not get the traffic to go through. I have this on a home network so I don't have a cpanel just cli.

Replies
us Donald Wood Replied 5 years ago

Bansh33 Thanks for the reply but I have a pretty extensive set of virtual servers and websites behind my nginx and I won't tare it all down to install another reverse proxy.
Arsalan Shah I will look into this when time permits. Thanks for the info.

us Rishi B Replied 5 years ago

I haven't tried using nginx, but I use ngrok as a reverse proxy with ossn without a problem. I have a local IP for a virtual machine running ossn, and I then launch ngrok with the command ngrok http -hostname=www.mysite.com 192.168.x.x:80 and it works without a problem or without any added config to either ngrok or ossn. The only thing needed was to set the url to http://www.mysite.com in ossn.config.site.php. I'm not running a site with an ssl cert for ossn, but I have another site on ngrok which is using an ssl cert and works fine when accessing it via https on abrowser. I suspect there wouldn't be any issue using an https site with ossn over ngrok, you'd just need to change the url to use https in the config file. Unfortunately I haven't really used nginx as I said earlier, so I can't be much help with that, but if your only need is a reverse proxy, you may want to look into alternatives like ngrok or localtunnel.

Indonesian Arsalan Shah Replied 5 years ago

Does your ngnix setting HTTP_X_FORWARDED_PROTO header for https? if so try to replace the ossn_redirect_absolute_url in ossn.lib.javascripts.php with below

function ossn_redirect_absolute_url(){
    $baseurl    = ossn_site_url();
    $parts      = parse_url($baseurl);
    $iswww      = preg_match('/www./i', $parts['host']);
    $host       = parse_url($_SERVER['HTTP_HOST']);
    $redirect   = false;
    $port       = "";
    if(!isset($host['host'])){
        $host = array();
        $host['host'] = $_SERVER['HTTP_HOST'];
    }
    if(isset($parts['port']) && !empty($parts['port'])){
        $port = ":{$parts['port']}";
        if ($parts['port'] == ':80' || $parts['port'] == ':443'){
            $port = '';
        }
        if($parts['port'] !== (int)$_SERVER['SERVER_PORT']){
            $redirect = true;
        }
    }
    if(isset($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https') !== false) {
        $_SERVER['HTTPS'] = 'on';
    }
    if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
        $_SERVER['HTTPS'] = 'on';
        $parts['scheme'] = 'https';
    }
    if(empty($parts['port']) && isset($_SERVER['SERVER_PORT']) && !empty($_SERVER['SERVER_PORT'])
        && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !=='443'){
        $redirect = true;
    }
    if($parts['scheme'] == 'https' && empty($_SERVER["HTTPS"])
        || (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" && $parts['scheme'] == 'http')) {
        $redirect = true;
    }
    if(($host['host'] !== $parts['host']) || $redirect){
        header("HTTP/1.1 301 Moved Permanently");
        $url = "{$parts['scheme']}://{$parts['host']}{$port}{$_SERVER['REQUEST_URI']}";
        header("Location: {$url}");
    }
}
Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions