I've set up the following virtual server in my NGINX conf:
server {
listen 80;
listen [::]:80;
server_name ip.myserver.com;
location / {
default_type text/plain;
return 200 "$remote_addr\n";
}
}
The idea is that I have some other virtual servers that I want to access only using the OpenVPN connection which is on the same machine. Using this test site, it should display the private IP address (or public if not connected to the VPN).
My Android phone works perfectly:
While connecting to the site without VPN connection it displays the following: 192.0.2.222
. (It has another address in reality, of course.)
When connecting to the site using the VPN connection, the following is displayed 10.8.0.3
, this is the correct result as it is showing that the device is using the VPN connection and since the VPN service and Nginx server are on the same machine, Nginx sees the private IP of the VPN.
When doing this on my Linux machine, it displays the Linux machine's public IP address when connecting to the server without a VPN connection, and when connecting with a VPN connection it displays the server's public IP address, which is not what I expected.
I suspect there's something wrong with the way OpenVPN is configured on my Linux laptop, as the Android phone is working fine.
OpenVPN Server Config:
port 1194
proto udp6
dev tun
user nobody
group nogroup
persist-key
persist-tun
keepalive 10 120
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "dhcp-option DNS 94.140.14.14"
push "dhcp-option DNS 94.140.15.15"
push "redirect-gateway def1 bypass-dhcp"
server-ipv6 fd42:42:42:42::/112
tun-ipv6
push tun-ipv6
push "route-ipv6 2000::/3"
push "redirect-gateway ipv6"
dh none
ecdh-curve prime256v1
tls-crypt /etc/openvpn/tls-crypt.key
crl-verify /etc/openvpn/crl.pem
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server_key.crt
key /etc/openvpn/server_key.key
auth SHA256
cipher AES-128-GCM
ncp-ciphers AES-128-GCM
tls-server
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
client-config-dir /etc/openvpn/ccd
status /var/log/openvpn/status.log
verb 4
OpenVPN Client File (Without keys):
client
proto udp
explicit-exit-notify
remote 192.0.2.222 1194 # Changed this for display.
dev tun
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
verify-x509-name server_key name # Changed this because not sure if private info
auth SHA256
auth-nocache
cipher AES-128-GCM
tls-client
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
ignore-unknown-option block-outside-dns
setenv opt block-outside-dns # Prevent Windows 10 DNS leak
verb 3