Score:0

How to run nginx and ocserv on the same IP:Port using the same domain name?

cy flag

How to run nginx and ocserv on the same IP:Port using the same domain name? Just like how a similar thing is possible by using SSTP protocol, if I am not mistaken. I am using Ubuntu 20.04.

Score:1
US flag
user1018817

Most likely what you want to do is configure Nginx to listen on the HTTPS port, and configure it to proxy through to your ocserv process running on a different local port. Nginx would need to decide which site to serve, and to differentiate it could key off either:

  • the host (e.g., vpn.yourdomain.com versus web.yourdomain.com).
  • the prefix path (e.g., web.yourdomain.com/vpn/).

The host would be the best approach. In that configuration, you would configure the two DNS entries to point to the same IP address. Nginx config would look something like this:

server {

# SSL configuration
#
listen 443 ssl default_server;


    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

    server_name web.yourdomain.com;

        location ~ / {
                root /var/www/html/blank/;

                try_files $uri $uri/ =404;
                allow all;
        }

}

server {

    # SSL configuration
    #
    listen 443;


    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name vpn.yourdomain.com;

    location / {

          proxy_pass_header Server;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_set_header X-Forwarded-For  $remote_addr;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-Scheme $scheme;
          proxy_connect_timeout 120s;
          proxy_read_timeout 600s;
          proxy_pass http://127.0.0.1:1234/;

    }


}

In that configuration, from the outside, both services would be available via the same IP/port (HTTPS/443). They'd use different DNS hostnames (web.yourdomain.com and vpn.yourdomain.com) both pointing to the same IP. Your ocserv process would be listening on local port 1234 in this example

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.