2 services on same hostname but different ports - port

I had 2 service on a server that run on 2 different ports. One of them on port 80 and another on port 3000. I want to address them like this:
http://xxx.ttt.example : the one that run on port 3000
http://xxx.ttt.example/zzz : the one that run on port 80
what should I do?

You need to use a reverse proxy server such as nginx to achieve this. As port can be mentioned only in SRV records at DNS level, and most browser ignore this record while resolving a dns query for a http request.
The domain will point to a reverse proxy server and at proxy server you can configure where to pull response from based on the request.
Setup -
Setup nginx reverse proxy server.
point your domain xxx.ttt.example to the nginx server.
In nginx config set a rule based on request uri fetch the response from port 3000.

Related

How can I access two different dockers in my server through two different ports?

I have a server with three main dockers:
Fron End docker: port 8080
Back End docker: port 88
Nginx Proxy Manager: port 80 and 443
I used Nginx Proxy Manager to create the SSL certificate and redirect to the dockers.
When I access the server with the url (https://url:443), the proxy will redirect to my Front End. This page will ask information to the Back End through the same url but with a different port (https://url:8443). I want to know how can I access to my Back End with this second port. The request lands on the server, the nginx proxy manager redirects to my front end again, cause there is a register that says url-->IP_server:8080, and I cannot url:8443-->IP_server:88.

Nginx proxy pass for ingress and egress

I would like to forward traffic using (reverse) proxy for both ingress and egress while manipulating the request and response URI's.
The scenario is this:
Ingress
Request from the internet (with request uri of "/test/") enters an ec2 instance on port 8888, it then goes into a Nginx docker container that listens on this port and proxy pass it to a second docker container while 'replacing' the request uri to be "/" on port 12345 (then inside the container forward it onto port 8787 to a web application).
Egress
The response that comes back from the second docker container to the Nginx container has to be "rebuild" again to the original uri ("/test/") and sent back as a response to the original client.
I think I got the ingress part by configuring the Nginx like this:
server {
listen 8888;
server_name 172.17.0.1;
location / {
proxy_pass "http://172.17.0.1:12345";
}
}
but it seems not quite right as I thought it should be using the Nginx itself (172.17.0.3) as the "server_name" and the web application (172.17.0.2) as the upstream, but that didnt work (502 error).
I'm attaching an image for this scenario, Thanks.
You can run both NGINX and Web App docker containers on the same network by creating a docker network and specifying the network while running the containers with the --network flag. With this setup, you wouldn't have to bind the host port (12345) while running the Web App and it would be accessible from the Nginx container on <webapp_container_name>:8787. So you can specify this in proxy pass - http://<webapp_container_name>:8787

Docker container redirecting

Hi i have a url called :
https://wona.logs.co.za
And i need it to redirect to the speciic docker container at port 3000
( http://156.43.123.226:3000)
However when i try link https://wona.logs.co.za to 156.43.123.226:3000 i cannot enter a port number in the redirection to specify my docker container
Multiple things that do not fit.
you try to redirect https traffic to an http endpoint. That won't wortk
you are trying to directly redirect to another port (from 443, to 3000). That won't work either.
Solution
Create a proxy container. e.g. nginx that serves port 80 / 443 and redirects traffic to your application on port 3000. I recommend that you do not directly expose your application - only via the proxy.
Once you have a proxy container that listens to the same ports you can easily use the redirect as you described.
The question lacks the current setup of docker on mentioned server. From what i understood, is you already have docker running with orchestrator and a proxy server for main domain, and now you want to put up a subdomain which forwards traffic to one specific container.
For this, you need to spin an image of your application which listens on port 3000, add an entry in proxy server to forward traffic to your new container. Handle the ssl handshaking at proxy level.

Docker containers serving different subdomains on port 80

Is it possible to have a 2 docker containers serve on port 80 but different subdomains or hostnames?
Something like:
api.example.com goes to a node application
app.example.com goes to a Java application
Yes you can. using a proxy.
There is a project by jwilder/nginx-proxy which allows you to give your hostname via an enviroment variable which will than route your request to the appropriate container.
A good example of this implemented is given here: https://blog.florianlopes.io/host-multiple-websites-on-single-host-docker/
No. The first container you start will have exclusive access to the port, and if you try and start a second container on the same port it will fail.
Instead, use a load balancer such as Nginx or Traefik to handle the incoming traffic to port 80 and proxy it on to your two app containers based on host headers.

remove port number from the url

I have two instances of tomcat on a single machine both instances accepting secure request. Suppose:
one has connector port configured as 8080 and redirect port as 443. The other one has connector port configured as 8083 and redirect port 444. So if first tomcat receive request as
http://localhost:8080/abc/index.html
it then redirect to https://localhost/abc/index.html
and if 2nd tomcat receive request as
http://localhost:8083/abc/index.html
it then redirects to https://localhost:444/abc/index.html
now my problem is that i want to remove that port number 444 from the url. Is there any way to remove that or hide that. I can't use same port number 443 for both the instance.
thanks
No you can't do that. The web browser will only connect on port 443 for HTTPS if you don't specify a port.
Bind an additional static IP address to your computer and assign the second Tomcat to use 443 on that address. Add to your hosts file to use a non-numeric name.
192.168.1.99 localhost2

Resources