Table of Contents
There are many way to share file on network. Mostly use network file sharing is CIFS and SAMBA. In this article we will discuss how we can perform file share over HTTP using Apache2 Web server file sharing on a Linux machine using distro Ubuntu. Using HTTP to download file is just like download file from some website which looks cool.
Setting up Apache2 Web server File Sharing
1. At first check your Linux machine OS version using command cat /etc/os-release, in my case it’s Ubuntu 20.
# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
2. Download and install Apache2 Web server for Web server File Sharing using the following comand:
sudo apt install apache2 -y
3. Once done, you can check the /var/www/html directory which contains default HTML page.
# ls -l /var/www/html/
total 16
-rw-r--r-- 1 root root 10918 Nov 16 10:04 index.html
4. Check if your Apache2 Web server is working by opening web browser and open default HTML page by typing the ip address of the Ubuntu machine in the address bar which should open a page as below:
5. Create a sub folder under html folder to store the public data.
mkdir /var/www/htlm/public
6. Now, using any FTP client to upload public files to the public folder on Ubuntu server.
# ls -l /var/www/html/public/
total 704824
-rw-r--r-- 1 root root 525508520 Nov 7 11:12 AcrobatPro_11_Web_WWMUI.exe
-rw-r--r-- 1 root root 3999808 Nov 15 08:30 AnyDesk.exe
-rw-r--r-- 1 root root 165841568 Nov 10 02:09 ExpanDrive_Setup_2022.7.1.exe
-rw-r--r-- 1 root root 1395272 Nov 2 01:05 rufus-3.20p.exe
-rw-r--r-- 1 root root 2132264 Nov 10 01:55 VisualStudioSetup.exe
-rw-r--r-- 1 root root 11377992 Nov 15 06:27 VNC-Viewer-6.22.826-Windows.exe
-rw-r--r-- 1 root root 11471704 Nov 1 07:18 WinSCP-5.21.5-Setup.exe
Create a virtual host for the http file server
1. Run the following command to disable the default site. If you don’t do this, when you access by typing ip address on the browser. It’s always show the default Apache welcome page.
sudo a2dissite 000-default
2. Create a virtual host configuration file. You can change the file name public.conf and the DocumentRoot /var/www/html/public to any directory as you need.
cat << EOF >> /etc/apache2/sites-available/public.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
3. Verify the virtual host is created in /etc/apache2/sites-available directory.
# ls -l /etc/apache2/sites-available/
total 16
-rw-r--r-- 1 root root 1332 Feb 23 2021 000-default.conf
-rw-r--r-- 1 root root 6338 Feb 23 2021 default-ssl.conf
-rw-r--r-- 1 root root 156 Nov 16 10:32 public.conf
4. Finally, enable the virtual host, test Apache configuration then reload Apache service.
sudo a2ensite public
sudo apache2ctl configtest
sudo systemctl reload apache2
As you can see, now the public http file server available to access from any computer in your network though any web browser.
Configure the HTTP file share with a domain name
Access the file shared via ip address look like not professional. And I want to access the file server through a domain name like http://files.bonguides.com.
To achieve that goal, I need:
- A DNS server to resolve the host name to the IP address of the Ubuntu server. It could be a public DNS when you bought a domain or a local DNS in Microsoft Active Directory, or you can create a DNS record in some routers and firewalls.
- Create a new virtual host with server name.
1. Remove the current virtual host configuration file.
rm /etc/apache2/sites-available/public.conf
2. Recreate the virtual host configuration file as follows:
cat << EOF >> /etc/apache2/sites-available/public.conf
<VirtualHost *:80>
ServerName files.bonguides.com
ServerAlias www.files.bonguides.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
3. Now, you can access the HTTP file server though a domain name instead of ip address.