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.

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.

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

Try DigitalOcean for free

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

Sign up

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.