I have a web application running on a Droplet, under Apache. The application is currently public.
I would now like to configure a VPN, to restrict access. I would then expect users of the application to gain access via VPN client software only.
How can I restrict my server application to a VPN?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Heya,
you’ll need to set up a VPN server on your Droplet and configure your Apache server to allow connections only from the VPN.
You can check this MarketPlace Droplet:
https://marketplace.digitalocean.com/apps/openvpn-access-server
Follow the steps on that page to configure a Droplet with OpenVPN on it.
Once you have that you’ll need to restrict access on the Droplet your App is only from the VPN.
Configure Apache
Edit Apache Configuration:
Open your Apache configuration file, usually located at
/etc/apache2/sites-available/000-default.conf
or similar.Restrict Access:
Add a
Require
directive to restrict access to the IP range used by your VPN. For example:This allows access only to clients connected to the VPN using the IP range
10.0.0.0/24
.To restrict your web application to VPN access only, follow these steps:
1.Set Up a VPN: Install and configure a VPN server on your Droplet (e.g., OpenVPN, WireGuard).
2.Configure Firewall Rules: Use firewall rules (e.g., UFW, iptables) to allow traffic only from the VPN network. Block public access to your web application port (typically port 80 or 443 for HTTP/HTTPS).
3.Update Apache Configuration: Modify your Apache configuration to listen only on the VPN network interface. This ensures that Apache serves your application only to VPN-connected clients.
4.Distribute VPN Credentials: Provide VPN client configuration files and credentials to authorized users.
By following these steps, only users connected to your VPN will be able to access your web application.