Make a subdomain to point on a specific port - linux

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.

Related

How to link node+express server to domain

I have a domain name pointing to my vps IP. But when I run my express server I have to set a port, usually I use 3000, so the only way to get in my website is specifying the port: www.mysite.com:3000.
How can I make my app run in my domain without adding any port? My first guess was setting also the port in my domain name provider (111.11.11.11:3000) but Godaddy doesn't let me to add the port.
How can I make it work?
Newbie question, I know, but i'm a first timer and haven't found any answer to this.
The correct way is to change the port its hosted on. The default port for http traffic is 80, the one for https is 443. I assume you are on linux, if so you need to give some special permissions as ports below 1024 are privileged ports.
TLDR: if running http, change your express config to 80, if https 443
If using express, you need to change express port from 3000 to 80 if you plan using HTTP or 443 if you plan using HTTPS.
This is assuming your VPS does not already use port 80 or 443 while running an HTTP server like apache or nginx.
If you are in this case you will need to set up a reverse proxy.
I went for Nginx solution, I could make the port forward really easy following this guide:
https://eladnava.com/binding-nodejs-port-80-using-nginx/
For those who face this problem, solution is much more easier than it could look at beginning.

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.

How to specify the port serving CherryPy app in the DNS entry?

I receive a "Port 80 not free" message when I try to serve my CherryPy app on port 80. Most examples I see show folks using other ports. If I use another port how do I specify the port serving my CherryPy app in the DNS entry?
We're using Easy DNS and from what I can tell there is no way to specify the port in the DNS entry. Is this standard or a restriction with our provider?
Want to achieve something like this:
XXX.XXX.XXX.XXX - www.domain.com:9595
Thanks in Advance!
Andrew
To publish the TCP port number for your web site in DNS, you can create an SRV record, but there is no point in doing that since there are probably exactly zero web browsers in existence that actually query SRV records to find out which port to connect to.
So since SRV doesn't work, the short answer is to your question is, you can't. If your web server runs on a different port than 80 (for HTTP) or 443 (for HTTPS) then it is only possible to access it by specifying the port number directly in the URL, like http://www.domain.com:9595/.
If you really prefer to have your web site appear to be on port 80 (for HTTP) or 443 (for HTTPS) and there is already another web server listening on that port, then you can see if you can configure the other web server to proxy requests to your web server. For example, if the other web server runs Apache, then:
<Location /foo>
ProxyPass http://localhost:9595/
ProxyPassReverse http://localhost:9595/
</Location>

deploying a node.js on a new domain

I have a server that runs different websites on different ports. All of them (but one) are Apache servers and thanks to webmin, I managed to have, for instance, example.com point to 123.123.123.123:80 and example.fr to 123.123.123.123:8000, somehow automatically
I am now running a nodejs server on the same machine, so the 80, 8000, and many other ports are already taken. My nodejs listens on 8008. I have another domain name, say example.org, and I want it to point to my nodejs website, but I simply don't know how to do that! I have updated the DNS and everything is pointing to 123.123.123.123 (my server's IP). I want to avoid using an ugly example.org:8008/ for everything on this node server. How can I make it point implicitly to the 8008 port?? I must add that I cannot afford to take down the apache servers ;)
DNS only provides name to ip address mapping. It cannot handle ports. What you can do instead is to set up a proxy server listening on port 80. The proxy server can then return data based on the host header.
Your best option is to just redirect the request from Apache. Otherwise you can use a reverse proxy like Nginx. Also, you can write a lightweight proxy in node... check out this page

Accessing Websites through a Different Port? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am wanting to access a website from a different port than 80 or 8080. Is this possible? I just want to view the website but through a different port. I do not have a router. I know this can be done because I have a browser that accessing websites through different ports, Called XB Browser by Xero Bank.
Thanks for the answers. So, if I setup a proxy on one computer, I could have it go from my computer, to another computer that then returns the website to me. Would this bypass logging software?
A simple way is to got to http://websitename.com:174, and you will be entering through a different port.
If your question is about IIS(or other server) configuration - yes, it's possible. All you need is to create ports mapping under your Default Site or Virtual Directory and assign specific ports to the site you need. For example it is sometimes very useful for web services, when default port is assigned to some UI front-end and you want to assign service to the same address but with different port.
You can use ssh to forward ports onto somewhere else.
If you have two computers, one you browse from, and one which is free to access websites, and is not logged (ie. you own it and it's sitting at home), then you can set up a tunnel between them to forward http traffic over.
For example, I connect to my home computer from work using ssh, with port forwarding, like this:
ssh -L 22222:<target_website>:80 <home_computer>
Then I can point my browser to
http://localhost:22222/
And this request will be forwarded over ssh. Since the work computer is first contacting the home computer, and then contacting the target website, it will be hard to log.
However, this is all getting into 'how to bypass web proxies' and the like, and I suggest you create a new question asking what exactly you want to do.
Ie. "How do I bypass web proxies to avoid my traffic being logged?"
No, as the server decides what port it is run on. Perhaps you could install a proxy, which would redirect the port, but in the end the connection would be made on port 80 from your machine.
You can run the web server on any port. 80 is just convention as are 8080 (web server on unprivileged port) and 443 (web server + ssl). However if you're looking to see some web site by pointing your browser to a different port you're probably out of luck. Unless the web server is being run on that port explicitly you'll just get an error message.
It depends.
The web server on the other end will be set to a certain port, usually 80 and will only accept requests on that specific port. Something along the chain will need to be talking to port 80 to the website.
If you control the website, then you can change the port, or get it to accept requests on multiple ports.
If the website is already talking on a different port, you can just use the colon syntax to reference another port (eg: http://server.com:1234 for port 1234).
If you want to use a different port on your client end, but you want to talk to port 80 at the web server end, you'll need to route traffic from port x to port 80. A common way to get this up and running is to use Port Fowarding. ssh can do this for you, see here for a Unix/technical overview or here if you're on Windows.
Hope that helps.
when viewing a website it gets assigned a random port, it will always come from port 80 (usually always, unless the server admin has changed the port) there's no way for someone to change that port unless you have control of the server.
If website server is listening to a different port, then yes, simply use http://address:port/
If server is not listening to a different port, then obviously you cannot.
Unless you're browsing through a proxy, the web servers hosting the sites you want to access must be configured to listen to a port other than 80 or 8080.
Perhaps this is obvious, but FWIW this will only work if the web server is serving requests for that website on the alternate port. It's not at all uncommon for a webserver to only serve a site on port 80.
You can only access a website throught the port that is bind with the http server.
Example: i hava a web server and it is listening for connections on port 123, the you only can get my pages connecting to my 123 port.
To clarify earlier answers, the HTTP protocol is 'registered' with port 80, and HTTP over SSL (aka HTTPS) is registered with port 443.
Well known port numbers are documented by IANA.
If you mean "bypass logging software" on the web server, no. It will see the traffic coming from you through the proxy system's IP address, at least. If you're trying to circumvent controls put into place by your IT department, then you need to rethink this. If your IT department blocks traffic to port 80, 8080 or 443 anywhere outbound, there is a reason. Ask your IT director. If you need access to these ports outbound from your local workstation to do your job, make your case with them.
Installing a proxy server, or using a free proxy service, may be a violation of company policies and could put your employment at risk.

Resources