Liferay's PortalUtil.getPortalURL troubles - liferay

I'm having problems understanding a line of code and the Liferay API documentation doesn't give details. The lines is this one:
StringBuilder url = new StringBuilder(PortalUtil.getPortalURL(cp.getVirtualHost(), PortalUtil.getPortalPort(), false));
I know the first parameter gets its value from the virtual host in the main configuration, and the third one if set to true gets you a https URL, but i don't know from where its getting the port, also when the port is 80 it doesn't get added to the url.
What i need is that the port doesn't show even if its different from 80, any ideas?

As far as I understand this is common line of code to determine URL of Liferay Portal in a portlet or a hook plugin.
I think, the port is simply determined from the current request.
The reason why port 80 isn't showing is because it's standart HTTP port and it will be used by default. So you can't hide port from URL if it's different from 80 (or 443 for secure connection).

Related

How can I remove the port from the url?

I want to hide my port number in NodeJS,
for example:- I was running on a port 4001,if I want to make a request for '/xyz' webhook I need to make a request as 'https://example.com:4001/xyz' in this I am not interested to show my PORT to others I want to mask or hide it from the public it should be as "https://example.com/xyz"
Please help me to setup as above
I'm assuming your using localhost to serve your app. Once you deploy to the web, the port number will be handled automatically as all http requests are routed to port 80 by default.
May be you have given port number in your code. just remove that, instead keep process.env.PORT or process.env.PORT || 4001. so that the server will take port 80 by default.
now you no need to add the port number while visiting the url.
tldr switch your nodejs app to run on port 80.
The existing answers are all correct but none explain the why. The HTTP protocol (your site is a http server) uses port 80 as a default, yet you are running your server on port 4001 so it needs to be explicitly stated. If you go to http://example.com you are actually making the http request on port 80, it just doesn't need to be explicitly stated as that is the assumed default. There is no difference between http://example.com:80 and http://example.com.
That being said there is no security need to "mask" or "hide" your port. If you switch it to 80 it isn't hidden it just doesn't need to be typed. The only reason to make this switch is because it is easier, shorter, makes your site look more professional ect.

Make a subdomain to point on a specific port

I already checked some topic about it but didn't find any solutions (if it's possible). I have a domain that points on my server on the port 80, but, I have another important webservice running on the port 8080.
I want to know if it's possible to create a subdomain like (admin.example.com) which points on port 8080.
Thanks
The simple answer is no. The server name is resolved by a DNS query to a single IP, to which port the connection is made is between the application and the server. For HTTP the conventional default port is 80 and HTTPS 443, if you need to use another port, you need to include it in your URL.
SRV entries in a DNS record can be used so resolve a hostname to a specific port, but this works reliably only for a handful of protocols that mandate its use.
Currently the preferable way is to set up your server with a reverse proxy to direct traffic by a specific server name (your subdomain, carried in the request headers) to your admin service. This is quite easily done using e.g. nginx.

Does'nt Liferay work at different ports?

I have developed a portal page using Liferay and the port number is 8080. I wanted to test SSO, I decided not to try with the existing one as there might be some problems and I might end up crashing the whole thing. As a result I downloaded a new liferay portal. Iadded it to the eclipse and ran the second server whose port number was changed to 8085. But the webpage displayed when the second server ran was still 8080 and the same page as the first portal. Later I downloaded the enterprise edition and did the same, still 8080: 1st portal. I changed the plugins, no progress. Later, I changed the port number of first one to 8090. The page was not being displayed at all. Why is it like this? I don't get it. Does liferay work with a single port or can't there be two Liferay portal at a time?
You can always navigate to exactly the port that you configure - given that the appserver actually serves connections to the port. Common mistakes that I see (assuming you're running tomcat):
People change server.xml to refer 8080 to 8090, but leave the other ports (8005 and 8009) untouched. This means that there are conflicts with two tomcats. If you run both tomcats at the same time, the second one will not start, because another program is already listening to 8005 and/or 8009). You'll need to change all ports to unique values (search server.xml for all declarations of port=
You're relying on the browser to automatically open. Liferay's portal-ext.properties allows to override the page to automatically open - either to being empty or to a specific other URL. Configure browser.launcher.url to your requirements (see below)
There might be other servers running on either port that you're trying to have tomcat - or any other appserver - listening on.
(Here's the default for browser.launcher.url)
# Enter a URL to automatically launch a browser to that URL when the portal
# has fully initialized. Enter a blank URL to disable this feature.
#
browser.launcher.url=http://localhost:8080

How to temporarely resolve a name to a localhost port?

I develop websites with rails, and I was looking for a simple way to setup a dynamic name resolution for my app. The final product I need is to is: Every time I start a rails application (by typing rails server on my application folder, I want to run it on a random port and if I type the application name on my browser (like myapp.dev or something) it resolves to the localhost on the correct port.
The part of getting the app name and generating a random port is not the problem. The problem is how to resolve a name to a local port. Is there any simple tool on linux that allows me to do this?
Right now, the best I can think off is start a daemon that keeps track of when a rails app is started, annotate the port, and add an entry to itself in /etc/host with the app name. Then, whenever it receives a request, it forward to the correct app based on the name.
I can't believe this is the best way so ideas are highly appreciated.
I'm not sure if I understand your problem correctly, but DNS it not about ports. By using DNS you can resolve the name to IP not port or from IP to name (RevDNS). What you would do in your case is during start up of application on random port, forward another port which will be always the same.
For instance:
By iptables forward port 80 to random port of your application. Then you will always get to application by port 80.
Edit: I couldn't paste it in the comment because it's too long, so I give you answer here:
You can create a lot of iptables rules and first application will be on port 80, next 81, and so on.In browser you have to type then: apps.test.com (first app) , apps.test.com:81 (second app)..
Another solution: if you want to have diffrent domains (not type a port after colon), you can use proxy server,
and use VirtualHost to redirect to particular apps. In proxy configuration you can define that app1.test.com goes to port e.g 8888, app2.test.com goes to port 8889 and then during start up your app you can create iptables rule or ssh tunel to redirect whole traffic from port 8888 to your random port of
ruby application. To don't do it more complicated, it would be nice that these port
which you configure in proxy, are not used by your ruby application. Also you can check, iptables
"string match" option; Match Host field of HTTP request and then analogously during start up apps,
create iptables rule which will redirect everything which goes to port 80 with specify Host field to
your ruby app port. The last option would be using SRV dns record, but it's rather useless in your
situation. But anyway you can play around with all of these options, and choose one which is the best for
you.

Local IIS, how do I map a URL with a port number?

I'm runnning IIS 7 on my local dev machine. My website is up and running. To access the website, I need to enter the url with the port number in the browser's address bar (www.ScoobyDoo.dev:91). What do I need to change so I only need to enter the www.ScoobyDoo.dev portion of the url? I've done this before but I'm drawing a blank. Port 80 is hosting a different website so I can't just move this one to the default http port.
Thanks!
If you want multiple sites to reside on the same IP address then you need to use HTTP Host Headers.
Provided that your existing website doesn't use SSL then you can use host headers. To configure host headers in IIS7 you modify the "Bindings" (there's a menu item for this in the right hand side Actions pane for the site):
You want to add/edit your bindings for each site that resides on the same IP address, for example for your scoobydoo.dev site:
The caveat here is that if you have users already browsing your first site by IP address then they will need to be redirected to the site using its domain name.
You can do this by adding a site bound to the raw IP address and creating a HTTP Redirect.
I'm not sure what you're expecting to do here. If something else is binding to port 80, and your web server is binding to port 91, then you'll need to specify port 91 in the web browser when making a request to the server. By default, without being explicitly given a port in the address, a web browser will make the request on port 80 (or 443 for SSL).
You might be able to add an entry to your hosts file (c:\windows\system32\drivers\etc\hosts) where you map the non-specified port version to the specified port version, but I don't think it'll work. That file is for DNS resolution, not port mapping. Worth a try though, I suppose.
Can you clarify a bit on what exactly you're expecting? Or what you think you may have done before? I wonder if you're not giving us the whole picture here.

Resources