How To Install the Apache Web Server with Proxy setup on Ubuntu V20

Nikhil Chaudhari
4 min readFeb 1, 2025

--

Hey its been long time i haven’t written blog, I was busy in other stuffs. So lets start with topic how to setup apache web server along with proxy setup and also covers what are security practices we can takes while setuping these all.

Introduction

The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.

Prerequisites

Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server. Additionally, you will need to enable a basic firewall to block non-essential ports.

Web server Setup

Step 1 — Installing Apache #

sudo apt update
sudo apt install apache2

Step 2 — Adjusting the Firewall

Before testing Apache, it’s necessary to modify the firewall settings to allow outside access to the default web ports.

List the ufw application profiles by typing:

sudo ufw app list


Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH

Since we haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80 and check status :

sudo ufw allow 'Apache'
sudo ufw status
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)

Step 3 — Checking your Web Server

Check with the systemd init system to make sure the service is running by typing:

 sudo systemctl status apache2

As confirmed by status output start and enable, the service has started successfully.

Try to browse the server using its ip :

http://your_server_ip:8080/

Step 4 — Managing the Apache Process

Now that you have your web server up and running, let’s go over some basic management commands using systemctl.

To stop your web server:

sudo systemctl stop apache2

To start the web server when it is stopped:

sudo systemctl start apache2

To stop and then start the service again:

sudo systemctl restart apache2

otherthings can you do with service reload disable enable :

sudo systemctl reload apache2
sudo systemctl disable apache2
sudo systemctl enable apache2

Setting Up Virtual Hosts (Recommended)

Create the directory for your_domain as follows:
sudo mkdir /var/www/your_domain

Next, assign ownership of the directory with the $USER environment variable:
sudo chown -R $USER:$USER /var/www/your_domain

The permissions of your web roots should be correct if you haven’t modified your umask value, which sets default file permissions. To ensure that your permissions are correct and allow the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, you can input the following command:
sudo chmod -R 755 /var/www/your_domain

Next, create a sample index.html page using nano or your favorite editor: sudo nano /var/www/your_domain/index.html

Inside, add the following sample HTML:
/var/www/your_domain/index.html

<html>
<head>
<title>Welcome to Your_domain!</title>
</head>
<body>
<h1>Success! The your_domain virtual host is working!</h1>
</body>
</html>

Save and close the file when you are finished.

In order for Apache to serve this content, it’s necessary to create a virtual host file with the correct directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf:
sudo nano /etc/apache2/sites-available/your_domain.conf

Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:
/etc/apache2/sites-available/your_domain.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Let’s enable the file with the a2ensite tool:
sudo a2ensite your_domain.conf

Disable the default site defined in 000-default.conf:
sudo a2dissite 000-default.conf

Next, let’s test for configuration errors:
sudo apache2ctl configtest

You should receive the following output:
Syntax OK

Restart Apache to implement your changes:
sudo systemctl restart apache2

Server Logs

If we see for logs generated by server then there are mainly two files :

/var/log/apache2/access.log :
By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise.

/var/log/apache2/error.log:
By default, all errors are recorded in this file. The LogLevel directive in the Apache configuration specifies how much detail the error logs will contain.

Conclusion

Finally we have setup our Apache2 web server. Continuing this project, in next blog i will setup Reverse proxy and load balancer for two or more servers.

--

--

Nikhil Chaudhari
Nikhil Chaudhari

Written by Nikhil Chaudhari

I am (🦊) Cloud Security Researcher | | SOC Analyst | Passionate about learning & writing new technologies, tools & automations.

No responses yet