Answer the question
In order to leave comments, you need to log in
How to give access to the site only via VPN?
I have a virtual machine with OpenVPN and Nginx installed.
You need to make sure that Nginx gives the user "from the Internet" 403 forbidden
, and if the user is connected to the VPN server - 200 OK
.
The Nginx setup is as follows:
server {
listen 80;
server_name localhost;
location / {
add_header "Content-Type" "text/html";
if ( $remote_addr !~ ^10\.6\. ) {
return 403 "($remote_addr) Forbidden\n"
}
return 200 "($remote_addr) Hello from internal network\n";
}
}
mode server
tls-server
server 10.6.0.0 255.255.255.0
ifconfig 10.6.0.254 10.6.0.253
route 10.6.0.0 255.255.255.0
push "route 192.168.0.0 255.255.255.0"
dev tun
verb 3
duplicate-cn
key key.pem
ca cert.pem
cert cert.pem
dh dh.pem
keepalive 10 60
persist-key
persist-tun
proto tcp-server
port 1194
$remote_addr
my real address will be in, and not the one in the VPN network. And Nginx believes 403.
How to make it so that when accessing the public IP, 200 is returned? curl <public_ip_of_vps> # Получаю 403
curl 10.6.0.1 # Получаю 200
Answer the question
In order to leave comments, you need to log in
Perhaps this solution will be the simplest: if the users of your VPN have access to the Internet and an external IP address, you can use htaccess htaccess.ru/info/ip-filtering to allow access to the site only from this IP address.
Add VPN users a route to the site's external IP address via VPN. This will not work if the site and the VPN server are located on the same IP address.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question