Nginx – OpenVPN doesn’t share port with nginx

httpsnginxopenvpnssl

I have OpenVPN configured to sent non-VPN traffic on port 443 to my nginx server on port 4433. When I go to https://domain.tld:4433 it works, although https://domain.tld (Where OpenVPN listens on port 443 TCP) results in an "Page not available" (ERR_CONNECTION_CLOSED in Chrome).

OpenVPN config:

port 443
proto tcp
port-share localhost 4433

Nginx config: (Not actually required, because I'm sure it works)

server {
    listen      1.2.3.4:4433;
    server_name domain.tld www.domain.tld;
    ssl         on;
    ssl_certificate      /home/rick/conf/web/ssl.domain.tld.pem;
    ssl_certificate_key  /home/rick/conf/web/ssl.domain.tld.key;
    error_log  /var/log/apache2/domains/domain.tld.error.log error;
    ...
}

Best Answer

This is how I solved it:

  1. Check whether OpenVPN is listening on Port 443 TCP. Check according to the config, as well as an port check service.
  2. Set port-share to port-share {IP} {PORT}

How to know the {IP} and {PORT}?

In nginx:

server {
    listen      {IP}:{PORT};
}

In Apache:

<VirtualHost {IP}:{PORT}>
    ServerName {IP} 
    ServerAlias {IP} 
// Could also be an hostname, hostname also work on OpenVPN port-share.
// When {IP} in the VirtualHost opening tag is "*", using localhost or 
// 127.0.0.1 or Public IP in OpenVPN, will fix the problem.
</VirtualHost>

Hope this helped you out!