Apache2 server administration – Handy guide

1- To restrict access to a port from certain ip address


root@docker-adb-01:~# cat /etc/apache2/sites-enabled/000-default.conf

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	< Directory /var/www/html/>    		
		Order Deny,Allow
		Deny from all
		Allow from your_ip_address_1
        Allow from your_ip_address_2
	< /Directory>
< /VirtualHost>

Then, you will only allow your ip addresses to access to your apache server through port 80.
You can replace port number, ip address and also directory as you prefer.

2- To restrict access to your proxy under virtual host from certain ip address


root@docker-adb-01:~# cat /etc/apache2/sites-enabled/001-default.conf

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	< Proxy *>
        Order deny,allow
        Allow from all
    < /Proxy>
    
	ProxyPreserveHost On
    ProxyPass / http://localhost:9090/
    ProxyPassReverse / http://localhost:9090/
	< Location />    		
		Order Deny,Allow
		Deny from all
		Allow from your_ip_address_1
        Allow from your_ip_address_2
	< /Location>
< /VirtualHost>

Then, you will only allow your ip addresses to access to your apache server through port 80.
You can replace port number, ip address and also directory as you prefer.

About: tientham

Software Engineer, SW Integrator & Mobile , Full Stack Developer


Leave a Reply

Your email address will not be published. Required fields are marked *