{{tag>dns proxy apache webserver}} ====== Proxying DNS name to local service ====== ===== Enable apache modules first ===== a2enmod proxy proxy_http ===== vhost configuration example for service running on port 8080 ===== Part to be added: ServerName sub.example.com ProxyPreserveHost On ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ **Note**: Put above in ssl configuration when redirecting to ssl ports. **Note**: If the first argument in ProxyPass directives ends with a trailing /, the second argument should also end with a trailing /, and vice versa. Otherwise, the resulting requests to the backend may miss some needed slashes and do not deliver the expected results. * ProxyPreserveHost makes Apache pass the original Host header to the backend server. This is useful, as it makes the backend server aware of the address used to access the application. * ProxyPass is the main proxy configuration directive. In this case, it specifies that everything under the root URL (/) should be mapped to the backend server at the given address. For example, if Apache gets a request for /example, it will connect to http://your_backend_server/example and return the response to the original client. *ProxyPassReverse should have the same configuration as ProxyPass. It tells Apache to modify the response headers from backend server. This makes sure that if the backend server returns a location redirect header, the client’s browser will be redirected to the proxy address and not the backend server address, which would not work as intended. ==== Restart apache2 ==== systemctl restart apache2 ====== Tested on ====== ===== See also ====== * [[Letsencrypt certificate via DNS authentication]] * [[wiki:proxy_non_http_traffic_through_nginx|Proxy non-http traffic through nginx]] ====== References ====== * https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04