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:frontend http_frontend bind *:80 mode http option httpclose reqadd X-Forwarded-Host:\ domain.com default_backend web_server backend web_server mode http balance roundrobin option httpclose option httpchk HEAD / HTTP/1.0 cookie JSESSIONID prefix server app1_1 127.0.0.1:8080 cookie A check
- Edit /etc/hosts file and add a custom domain name for localhost you added in previous step:
127.0.0.1 domain.com
- Enable custom http headers for URL in portal-ext.properties:
web.server.forwarded.host.enabled=true
- 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".