To change the default port and/or IP binding for Apache2 on Debian or Ubuntu, you will need to edit the Apache configuration file.
By default, Apache listens on port 80 for HTTP traffic and port 443 for HTTPS traffic, and it binds to all available network interfaces.
To change the default port, you will need to modify the Listen
directive in the Apache configuration file. This directive specifies the port that Apache should listen on.
For example, to change the default port to 8080 for HTTP traffic, you can add the following line to the Apache configuration file:
Listen 8080
To change the default port to 8443 for HTTPS traffic, you can add the following line to the Apache configuration file:
Listen 8443
To bind Apache to a specific IP address or network interface, you can use the Listen
directive along with the IP address or interface name.
For example, to bind Apache to the IP address 192.168.0.10
, you can add the following line to the Apache configuration file:
Listen 192.168.0.10:80
To bind Apache to the eth0
network interface, you can add the following line to the Apache configuration file:
Listen eth0:80
It's worth noting that you may need to update your firewall rules to allow traffic on the new port.
After making changes to the Apache configuration file, you will need to restart the Apache service to apply the changes.
sudo systemctl restart apache2
It's a good idea to make a backup of the Apache configuration file before making any changes, in case you need to revert the changes. You can do this with the following command:
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.backup