Beginner Fundamentals
Ports and the Listen Directive
The Listen directive tells Apache which network ports to bind to. Without it, Apache would not accept any connections.
Standard Ports
- Port 80 is the default for plain HTTP.
- Port 443 is the default for HTTPS (encrypted).
Basic Usage
Listen 80
Listen 443
On Debian this lives in /etc/apache2/ports.conf. On Red Hat it is in httpd.conf.
Listen on a Specific Address
You can bind to one IP address instead of all of them:
Listen 192.168.1.10:80
Custom Ports
You can run Apache on any free port, useful for testing:
Listen 8080
A virtual host must match the port it serves:
<VirtualHost *:8080>
ServerName test.local
DocumentRoot /var/www/test
</VirtualHost>
Check What Is Listening
sudo ss -tlnp | grep apache
After changing ports, reload Apache and make sure your firewall allows the new port.