AI Overview
- Different Ports: This is the simplest method. Configure one server (e.g., Apache) to listen on a non-standard port like
8080or81, while the other (e.g., Nginx) uses the default80(HTTP) and443(HTTPS) ports. Users would access the second server by appending the port number to the URL (e.g.,http://yourdomain.com:8080). - Different IP Addresses: If your server has multiple IP addresses, you can bind each web server to a unique IP address on the same port (80/443).
- Nginx as a Reverse Proxy (Recommended):
This leverages the strengths of both servers. Nginx (known for speed
and efficiency in static content and high concurrency) listens on the
public ports
80and443. It serves static files directly and proxies requests for dynamic content (like PHP applications that rely on.htaccessfiles) to Apache, which is configured to listen on an internal, loopback IP and port (e.g.,127.0.0.1:8080). This setup improves overall performance and resource usage.
- Configure Apache to use a different port: Edit the Apache configuration files (
ports.confand the default virtual host file) to change the listening ports from80/443to an internal port like8080. - Configure Nginx as a reverse proxy: Set up Nginx to listen on the public ports
80/443. For dynamic requests, add proxy directives within the Nginx virtual host configuration to forward traffic to the Apache port (e.g.,proxy_pass http://localhost:8080;). - Install
mod_rpaf(ormod_remoteip) on Apache: This module ensures Apache logs the client's real IP address instead of Nginx's localhost IP, which is useful for statistics and authentication. - Restart services: After configuration changes, restart both Nginx and Apache to apply the new settings.