Score:0

How to setup port to subdomain in AWS?

cn flag

I have a domain (e.g. example.com) registered with godaddy.com and use AWS for hosting. Nameserver on Godaddy later added to AWS

enter image description here

I have an ubuntu (t2.medium) apache server installed. My project in Docker has LAMP, ELK, Node, React, and Postgres installed. Everything works on the local system using direct ports. Few ports open in my project i.e.

  • example.com:3000 react app [frontend]
  • example.com:5601 kibana app
  • example.com:5050 postgradmin app
  • example.com/radius php application [backend]
  • example.com:8080 phpmyadmin app

my desired URLs are:

I have tried a few things but nothing is working. on route53 enter image description here

tried reverse proxy on apache by adding separate conf files e.g.

default.conf

<VirtualHost *:80>
    ServerAdmin contact@example.com
    DocumentRoot "/var/www/html"
    ServerName example.com
    <Directory "/var/www/html/">
        AllowOverride all
    </Directory>
</VirtualHost>

kibana.conf

Listen 5601

<VirtualHost *:5601>
    ServerAdmin contact@example.com
    ServerName kibana.example.com
</VirtualHost>

pgadmin.conf

Listen 5050

<VirtualHost *:5050>
    ServerAdmin contact@example.com
    ServerName pgadmin.example.com
</VirtualHost>

when I run docker-compose up on EC2, http://example.com/radius works fine. but others do not (e.g. http://kibana.example.com). but if try with port directly (e.g. example.com:5601) it's working. but I want to use a sub-domain not a domain with a port.

How to do that?

reverse proxy I tried as mentioned in the description but it's not working properly

dummyuser avatar
uy flag
Using a reverse proxy is absolutely required for your use case. Within docker I recommend using [traefik](https://doc.traefik.io). It is a bit tricky to configure. Additionally I recommend a wildcard DNS and a wildcard certificate if you want to use https instead of http.
Gobinda Nandi avatar
cn flag
thanks... will check and update :)
George avatar
cn flag
This question should not belong here as it is not related to Ubuntu.
Gobinda Nandi avatar
cn flag
@dummyuser thanks for the suggestion, I added traefik in docker. The local env is working great with multiple subdomains, now checking on route 53.
Score:1
cn flag

Found the solution, comment please if this approach is wrong.

Added my sub-domains in AWS route53:

aws-route53

In docker-compose.yml file, added traefik and added my other images on the same network (t2_proxy)

traefik:
  image: "traefik:v2.9"
  container_name: $DOCKER_IMAGE_TRAEFIK
  command:
    #- "--log.level=DEBUG"
    - "--api.insecure=true"
    - "--providers.docker=true"
    - "--providers.docker.exposedbydefault=false"
    - "--entrypoints.web.address=:80"
  ports:
    - "80:80"
    - "8080:8080"
  labels:
      - traefik.enable=true
      - traefik.http.routers.api.rule=Host(`$DOCKER_TRAEFIK_HOST_PROXY`)
      - traefik.http.routers.api.entrypoints=web
      - traefik.http.routers.api.service=api@internal
    #  - traefik.port=8080"
  volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"
  networks:
    - t2_proxy
    - postgreNetwork
    - elk

In this config, $DOCKER_IMAGE_TRAEFIK is traefik image name from my .env file. You can add your image name and $DOCKER_TRAEFIK_HOST_PROXY is the host name e.g. proxy.example.com

for port configuration:

phpmyadmin:
  image: phpmyadmin:latest
  platform: linux/amd64
  container_name: $DOCKER_IMAGE_PHPMYADMIN
  links:
    - mysqldb
  networks:
    - t2_proxy
  environment:
    PMA_HOST: mysqldb
    PMA_PORT: ${MYSQL_PORT:-3306}
  # ports:
    # - "${PHPMYADMIN_PORT:-7865}:80"
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.phpmyadmin.rule=Host(`$DOCKER_TRAEFIK_HOST_PHPMYADMIN`)"
    - "traefik.http.routers.phpmyadmin.entrypoints=web"
    - "traefik.http.routers.phpmyadmin-rtr.tls=true"
    - "traefik.port=$PHPMYADMIN_PORT"
  volumes: 
    - /sessions

In this config, $DOCKER_IMAGE_PHPMYADMIN is phpmyadmin image name and $PHPMYADMIN_PORT is 7865 from my .env file. You can change as you want. $DOCKER_TRAEFIK_HOST_PHPMYADMIN is the host name e.g. phpmyadmin.example.com

In this example. I have blocked port access and I can access the sub-domain properly. the same setting for LAMP, ELK, Node, and React in my project.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.