I want to run a service on a custom port (e.g. jenkins on 8080) and I prefer to access it via browser with a name I can remember, e.g. http://localhost:jenkins
which will be an alias for http://localhost:8080
- Is such a thing possible?
- If so, will it be only an HTTP thing, or all network protocols will know of this alias?
- Also, if (1) is true, is this feature supported on other OS (centos, windows, etc.)
Edit:
- What are the moving parts from the moment I type in address until it gets resolved? I'm guessing that the browser parsers, and therefore there might be a browser that supports my request. After that, the parsed url is probably passed to an OS process which in turn can also implement my request and accept str instead of an int... Are any of these parts configurable in a such a way that it will answer my need?
This can be solved with "reverse proxying" - so research into this field a bit.
It can't do what you're actually asking (alias a port number), but it can give you another way to make an easy path for each service (by forwarding DNS records to a specific IP and port).
Basically, what you can do with a reverse proxy is:
HTTPS
in this casehttp://localhost:8080
tohttps://jenkins.local
(port forward)http://localhost/jenkins
tohttps://jenkins.local
(location forward)The above works with both internal and external DNS resolving
I'm personally using Nginx Proxy Manager, but Traefik is also a popular choice.
To get an idea what to setup, Nginx Proxy Manager looks like this:
From rfc 1738 https://datatracker.ietf.org/doc/html/rfc1738#section-3.1
port in the url is a number
It is possible to use solutions such as Nginx, Apache, squid, lighthttpd, etc. Do note that these will map your port to whatever name you give but it will be something independent from the internal localhost. You can use this software in Linux and window based systems.
Here's an apache example.
Another solution, if you wish to keep the servers memorable, is to give Jenkins a different IP all together by running it on a different server and then mapping it in
/etc/hosts
as192.168.1.1 Jenkins
(You basically add this in the file). After doing this let us say your Jenkins is running on192.168.1.1:3000
you can access it byhttp://jenkins:3000
.Even if you do this, all network protocols won't work, you won't be able to access Jenkins using
https://jenkins:3000
.Hope this helps!!
Probably the simplest solution is to use
redir
to redirect the ports, e.g. runredir :80 127.0.0.1:8080
, or even better put it into yourinetd.conf
. If you do not like the traffic going wastefully through another process, the same can be achieved usingiptables
forwarding (but that is more hassle).True way of creating an alias would be to use a SRV record in your DNS server and that would work well with no overhead, but because of history, SRV records are ignored for the http/https protocol.