Disable public access to my apache2 server

5,394

Solution 1

Maybe is better to enable firewall? UFW can allow access from host/network and deny for the rest of the world.

sudo ufw enable
sudo ufw allow from xxx.xxx.xxx.xxx/zz to any port 80 proto tcp

xxx.xxx.xxx.xxx - represent your local network, zz reprezent network mask

You can list rules with command

sudo ufw status

or

sudo ufw status numbered

Solution 2

I found it!

sudo nano /etc/apache2/apache2.conf

Scroll down till <Directory /var/www/>

Add these two lines before </Directory>

Deny from all
Allow from 127.0.0.1

This will deny access from any IP except 127.0.0.1, which is your own machine. If your network's IP is in the form of 192.168.x.x then allowing access from 192.168. will allow access to anyone in your network.

Share:
5,394

Related videos on Youtube

Nguyen Quang Anh
Author by

Nguyen Quang Anh

My name is Mohamed Khamis, I research in Human-Computer Interaction and Human-centered Security. As of September 2018, I am a Reader/Associate Professor at the University of Glasgow. I received my PhD from Ludwig Maximilian University of Munich (LMU) in Germany. More about me on my website: http://www.mkhamis.com

Updated on September 18, 2022

Comments

  • Nguyen Quang Anh
    Nguyen Quang Anh over 1 year

    I've just installed apache2 on my Ubuntu 14.04

    My server is now accessible from anywhere if the right IP was provided. I want to disable that so that only users within my local network would be able to access the server.

    I presume it has to be done from apache2.conf

    P.S. I am sure this question has been asked before, but I think I lack the correct keywords to find a previous post :)

  • Mohammad Hossein
    Mohammad Hossein about 3 years
    works fine in ubuntu 20.04LTS