You are not logged in.

#1 2020-05-28 10:50:13

karcher
Member
Registered: 2018-01-09
Posts: 140

[SOLVED] Accessing web services on localhost by hostname/domain name

Hi all,

I would like to access web services running on my localhost with hostname/domain name instead of IP:Port. I mean this kind of mapping:
127.0.0.1:8081 -> mysite1.local
127.0.0.1:8082 -> mysite2.local
etc.

Any idea how can it be done?

I can access some machines in my LAN this way after I've configured the DNS Resolver settings in my pfSense router, but I don't know how can I do something similar on my localhost. I've tried once in the past with dnsmasq, but I couldn't configured it correctly and had issues.

Last edited by karcher (2020-05-28 14:42:59)

Offline

#2 2020-05-28 12:30:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

man hosts

EDIT: wait, you want names for ports?  Nevermind, I'm not sure there is any practical way to do that.  You can easily have various names for static IP addresses, but domain names refer to domains, not ports.  You could run nginx or another reverse proxy to forward each domain name to the right port.  If you really do need the ports to be determined by the name, then this is what I'd do.

Last edited by Trilby (2020-05-28 12:37:08)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2020-05-28 13:11:00

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

Thanks for the response!

you want names for ports?

So to say.

You could run nginx or another reverse proxy to forward each domain name to the right port.

Hmm. I know that a reverse proxy can be used in front of web servers. Is it normal to use it also for desktop computers?

Offline

#4 2020-05-28 13:19:54

Zod
Member
From: Hoosiertucky
Registered: 2019-03-10
Posts: 629

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

In a pinch, browser bookmarks do a fair job.

Offline

#5 2020-05-28 13:28:38

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 1,975
Website

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

@Zod: We don't know any application details. Bookmarks are fine for storing the URI for the client (web browser), but are useless if you want to make Ajax calls to those "domains".
Some more background from the OP might clear up what intention is behind that setup to deliver a more targeted answer.
But so far, a proxy seems like a good idea. If the amount of separated local web services is high enough, OP might also want to consider using Unix Domain Sockets.

Last edited by schard (2020-05-28 13:29:22)


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Online

#6 2020-05-28 13:45:26

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

Some more background from the OP might clear up what intention is behind that setup to deliver a more targeted answer.

Right. I need this setup for Web Development, mapping sites/apps to names instead of ports.
E.g.:
http://mysite.local
or
http://mysite.local.dev

instead of:

http://localhost:3000

Last edited by karcher (2020-05-28 13:45:46)

Offline

#7 2020-05-28 14:05:27

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,772

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

Run nginx or lighttpd as a service on port 80.  Create proxy rules in the appropriate configuration files to rewrite the URLs and forward them to your software that is on ports 8081 and 8082
 
Squid might technically be the better choice, but its caching (which is what it does) might cause confusion as you change the backend service.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2020-05-28 14:42:38

karcher
Member
Registered: 2018-01-09
Posts: 140

Re: [SOLVED] Accessing web services on localhost by hostname/domain name

OK. Many thanks to all!

Offline

Board footer

Powered by FluxBB