Question

Restrict Droplet web app to VPN.

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?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

KFSys
Site Moderator
Site Moderator badge
August 5, 2024

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

  1. Edit Apache Configuration:

    Open your Apache configuration file, usually located at /etc/apache2/sites-available/000-default.conf or similar.

  2. Restrict Access:

    Add a Require directive to restrict access to the IP range used by your VPN. For example:

<Directory /var/www/html>
    Require ip 10.0.0.0/24
</Directory>

This allows access only to clients connected to the VPN using the IP range 10.0.0.0/24.

  1. Restart Apache:
sudo systemctl restart apache2

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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
Animation showing a Droplet being created in the DigitalOcean Cloud console