Objective: By the end of this lesson, you will be able to configure Apache to listen on a new HTTPS port (7199) and forward all traffic to an HTTP service running on port 5199.
Prerequisites:
- Basic understanding of Apache configuration.
- Access to Apache configuration files.
- An active HTTP service running on port 5199.
Lesson Content:
- Introduction to Port Forwarding and Apache Configuration:
- Explanation of port forwarding and its use cases.
- Overview of Apache as a web server and reverse proxy.
- Step 1: Configure Apache to Listen on a New Port (7199):
- Edit the Apache main configuration file (
httpd.conforapache2.conf). - Add the following line to tell Apache to listen on port 7199:
Listen 7199
- Save and close the file.
- Edit the Apache main configuration file (
- Step 2: Set Up a New VirtualHost for SSL on Port 7199:
- Navigate to your SSL configuration file (typically located in
/etc/apache2/sites-available/or a similar directory). - Create a new VirtualHost block for port 7199 with the following configuration:
SSLEngine on<IfModule mod_ssl.c>
<VirtualHost *:7199>
ServerName www.yourdomain.com
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
Include /etc/letsencrypt/options-ssl-apache.conf# Reverse Proxy Configuration
ProxyRequests Off
ProxyPass / http://localhost:5199/
ProxyPassReverse / http://localhost:5199/<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
</IfModule>Replace
/path/to/your/certificate.crtand/path/to/your/private.keywith the paths to your SSL certificate and private key.
- Navigate to your SSL configuration file (typically located in
- Step 3: Restart Apache to Apply Changes:
- Execute the following command to restart Apache:
sudo systemctl restart apache2
- This will make Apache start listening on the new port with the specified configuration.
- Execute the following command to restart Apache:
- Step 4: Testing the Configuration:
- Open a web browser and navigate to
https://www.yourdomain.com:7199. - Verify that the content served is being proxied from the HTTP service running on port 5199.
- Open a web browser and navigate to
- Step 5: Firewall Adjustments (If Necessary):
- Ensure that your server’s firewall allows traffic on port 7199.
- Conclusion and Troubleshooting Tips:
- Recap of what we’ve accomplished.
- Common troubleshooting tips if the setup doesn’t work as expected.
- Implement the port forwarding setup on your Apache server.
- Test the configuration by accessing your service at
https://www.yourdomain.com:7199. - Document any challenges faced and how you resolved them.
Additional Resources:
- Apache official documentation for mod_proxy: Apache mod_proxy
- Guide to installing and configuring Apache: Apache Configuration Guide
Feedback and Support:
- For any queries or issues, consult the Apache community forums or reach out to a network administrator for assistance.
