Securing your Apache web server with Firewalld is essential for managing incoming and outgoing traffic. If http and https services are absent, don’t worry; I will show you how to add them. Here’s the complete guide:
Step 1: Install Apache Web Server
Ensure that Apache is installed and running:
- Update your system:
sudo yum update
- Install Apache:
sudo yum install httpd
- Start and enable Apache:
sudo systemctl start httpd
sudo systemctl enable httpd
Step 2: Verify Firewalld Installation
Check if Firewalld is installed and running:
sudo systemctl status firewalld
If it’s not running, start and enable it:
sudo systemctl start firewalld
sudo systemctl enable firewalld
Step 3: Check and Add HTTP/HTTPS Services
To ensure that your Apache server can communicate properly, HTTP and HTTPS services need to be enabled. Here’s how:
-
List Available Services
Check if
httpandhttpsservices are available:
sudo firewall-cmd --get-services
If they are listed, proceed to add them in the next step.
-
Manually Add Missing Services
Ifhttporhttpsis missing, create a custom service file:- Navigate to the services directory:
cd /etc/firewalld/services/
-
Create a new XML file (e.g.,
http.xml) for HTTP:
sudo nano http.xmlAdd the following content:
<?xml version="1.0" encoding="utf-8"?> <service> <short>HTTP</short> <description>Web server HTTP service</description> <port protocol="tcp" port="80"/> </service>Repeat the steps for
https.xml, using port443. -
Reload Firewalld to register the services:
sudo firewall-cmd --reload
- Enable HTTP/HTTPS Add the services permanently to Firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
Reload to apply changes:
sudo firewall-cmd --reload
Step 4: Verify Firewall Rules
After adding the services, verify they are active:
sudo firewall-cmd --list-all
You should see http and https listed under the services.
Step 5: Test Apache Access
Confirm your setup by accessing your Apache server:
- Open a web browser and visit:
- HTTP:
http://your_server_ip - HTTPS:
https://your_server_ip
- HTTP:
- You should see the Apache default page.
By following these steps, you’ve ensured that your Apache server is configured securely with Firewalld, even if http and https were missing initially. This setup protects your web server and allows seamless communication.
Top comments (0)