Part to be added:
<VirtualHost *:80>
ServerName sub.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
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.