はじめに
SoftEther VPN Serverと、nginxのHTTPSでTCP 443ポートを共有するためのメモです。
構築後のイメージは、以下のようになります。
[Client]
|
TCP 443
|
[haproxy]
|
|
--------------------------------
| |
TCP 5555 TCP 10443
| |
[SoftEther VPN Server] [nginx]
環境
Ubuntu 22.04 LTS
前提
- SoftEther VPN Serverへの接続はSoftEther VPN ClinetとSSTPを利用することを想定しています。
- SoftEther VPN Serverへの接続と、nginxへの接続を判別するため、TLSのSNI(Server Name Indication)を利用します。
そのためSoftEther VPN Server用のFQDNと、nginx用のFQDNは別々にする必要があります。以下の記載はSoftEther VPN Server用(vpn.example.com)、nginx用(www.example.com)として記載しています。 - SoftEther VPN Serverとnginxは同一マシンにインストールされている想定です。
- haproxyでTCP 443を利用するため、SoftEther VPN ServerおよびnginxでTCP 443ポートは事前に明け渡す必要があります。
- SoftEther VPN ServerはTCP 443ポートを停止し、TCP 5555ポートで待ち受けるようにしておきます。
- nginxはTCP 443ポートをTCP 10443ポートに変更しておきます。
haproxyの構築
SoftEther VPN Serverへの通信と、nginxへの通信を振り分けるために、haproxyを利用します。
1.haproxyのインストール
$ sudo apt install haproxy
$ sudo systemctl start haproxy
$ sudo systemctl enable haproxy
2.haproxyの設定ファイルを作成
$ sudo vi /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
frontend https
bind *:443 # 443ポートで待ち受け
mode tcp # tcpモード(L4モード)
option tcplog
log global
timeout client 30000
tcp-request inspect-delay 5s
acl SoftetherACL req.ssl_sni -i vpn.example.com # SoftEther向けFQDN
acl WebserverACL req.ssl_sni -i www.example.com # nginx向けFQDN
tcp-request content accept if { req.ssl_hello_type 1 }
use_backend SoftetherVPN_ipvANY if SoftetherACL
use_backend Webserver_ipvANY if WebserverACL
backend SoftetherVPN_ipvANY
mode tcp
id 100
log global
timeout connect 30000
timeout server 30000
retries 3
server SoftEtherVPN localhost:5555 id 101 # SoftEtherのTCP 5555ポートに転送
backend Webserver_ipvANY
mode tcp
id 102
log global
timeout connect 30000
timeout server 30000
retries 3
server Webserver localhost:10443 id 103 # nginxの10443ポートに転送
3.haproxyの再起動
$ sudo systemctl restart haproxy
動作確認
- SoftEther Clientから接続する際は、クライアントの設定で「UDP高速化機能を無効にする」を有効にして接続する必要があります。
- SSTPは特にクライアントの設定変更は不要です。