Right now, it isn't possible to configure Liferay for creating URL in a dynamic way using a load balancer/proxy.
The only chance is having a "fixed" port and protocol using web.server.host and web.server.protocol properties. But this solution won't work if we want to have SSL offloading (so all the request to Liferay will go in http) and we want to access proxy using non-ssl protocol.
To improve this, we can implement a solution that is app-server agnostic and can be applied to many web servers/proxies (as Apache, haproxy, nginx, etc). We can use custom http headers so Liferay can read through them the data needed to create the URL.
Steps to reproduce:
- Install any web server proxy that can be configured to add custom HTTP headers (haproxy or Apache for example). Configure this proxy to startup on port 80 and to add a custom http header with name "X-Forwarded-Host". You can add the domain you want as the header value.
Haproxy configuration example:
- Edit /etc/hosts file and add a custom domain name for localhost you added in previous step:
- Enable custom http headers for URL in portal-ext.properties:
- Startup Liferay and web server proxy.
- Access http://localhost
- Examine HTML markup
Expected behavior: URL in <head> section are starting with "domain.com".
Actual behavior: URL in <head> section are starting with "localhost".