Foren

Creating proper URLs with Liferay behind a proxy

Patrick Spenke, geändert vor 9 Jahren.

Creating proper URLs with Liferay behind a proxy

New Member Beiträge: 7 Beitrittsdatum: 30.09.14 Neueste Beiträge
Hi Community,

I'm using Liferay 6.2 on a virtual machine running Windows Server 2008. This vm is located inside a net of an orgaisation and is called something like mymachine.local. Liferay is accessible via a proxy with the URL mydomain.com at port 8080 . By trying to access Liferay from the outside the css isn't loaded and the links doesn't work either, because Liferay creates absolut URLs with the name of the vm. Changing the URLs with firebug shows that it would work with either taking relative URLs or by using the name of the proxy instead without the port. The command "web.server.host=" in the portal.properties allows to change the host to the proxy but "web.server.port=" doesn't allow not to type the port into theURL afaik. Is there a possibility that Liferay creates URLs like http://mydomain.com/welcome-theme/... instead of http://mydomain.com:8080/welcome-theme/... or is the cause of this problem maybe somewhere else?
thumbnail
Christoph Rabel, geändert vor 9 Jahren.

RE: Creating proper URLs with Liferay behind a proxy

Liferay Legend Beiträge: 1554 Beitrittsdatum: 24.09.09 Neueste Beiträge
Well, since you didn't write what kind of proxy you are using, I will explain it with Apache.
Liferay uses the hostname it receives from the proxy!

I guess your proxy does something like this:

ProxyPass / http://mymachine.local:8080/
(Or maybe it uses a Location block, in the end it doesn't matter)

What happens here is that the host is set to mymachine.local:8080 by Apache and Liferay thinks that the client wants to talk to mymachine.local. So it prefixes all(or at least most) urls with it.

Add the following directive to Apache config:

ProxyPreserveHost On

This tells the Apache to send the original hostheader to the Liferay server. Another, very recommended approach is to use ajp protocol instead of http. It's quite simple, you just need to write:
ProxyPass / ajp://mymachine.local:8009/

ajp is basically an Apache/Tomcat specific optimized protocol. Note the port, it's 8009 in a standard Tomcat installation.

In case you use nginx as a reverseproxy, this should do the magic:
proxy_set_header Host $host;

If you use a different reverse proxy, it should have a similar directive.
Patrick Spenke, geändert vor 9 Jahren.

RE: Creating proper URLs with Liferay behind a proxy

New Member Beiträge: 7 Beitrittsdatum: 30.09.14 Neueste Beiträge
The settings for the apache server were the solution. Everything is working fine now. Thank you very much for your help.
thumbnail
Sushil Saini, geändert vor 9 Jahren.

RE: Creating proper URLs with Liferay behind a proxy

Regular Member Beiträge: 104 Beitrittsdatum: 27.07.11 Neueste Beiträge
You can set value of property web.server.port=80

80 is default port . When you Don't specify the port number in the url.