I searched already that it has something to the redirect module in apache, but I decided to ask here if someone can give me a direction where I should follow, because I am a bit lost.
The current situation is: I have a droplet with CentOS 7 x64 and within this droplet my docker user with some docker containers (just showing 2 to better exemplify):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f381c6a9a341 image1 "docker-entrypoint..." 4 weeks ago Up 3 weeks 0.0.0.0:15435->5432/tcp app1_postgres
69fb1e99b463 image2-nodejs_web "/docker-entrypoin..." 3 weeks ago Up 3 weeks 0.0.0.0:10443->443/tcp app1_nodejs
There is a container for the nodejs app and another container of the database for this app. Everything works and they can communicate with each other.
Besides, in this same droplet (outside docker) I have the user apache where I run httpd with my static portfolio in my custom domain https://www.myportfolio.dev.
What I would like: If I access https://www.myportfolio.dev/apps/app1 it redirects somehow from the apache to the docker container running my nodejs app in the exposed port 10443.
What I could do until now: if someone access https://www.myportfolio.dev:10443, which is the https port I have opened for the nodejs container, the app is accessible, but this is not the approach I want. I want to have the /apps/APP_NAME in the url redirecting to the specific containers.
Additional info 1: I usually have routes in my nodejs and react apps, for example:
https://myapp.com/ https://myapp.com/login https://myapp.com/home https://myapp.com/products https://myapp.com/insert
among other routes, and the redirect should work fine for this routes also.
Additional info 2: Either in my portfolio either in my apps I always use SSL. Please correct me if I am wrong, but the SSL key pairs for my portfolio can also be used for all my apps, because the apache httpd remains the same, it will be used as a “proxy” !?
Additional Question: Should I also create a subdomain for this app from the example before I configure them in apache? Something like CNAME e.g. myapp1.myportfolio.dev?
I would be really thankful for every help I receive here.
Thanks in advance!
Best Regards, Gabriel
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there @gabrielbrde,
What you could do is configure Apache as a reverse proxy, that way you can have the traffic for specify different URLs to be proxied to specific Docker containers, for example, it would look something like this:
ProxyPreserveHost On
ProxyPass /apps/APP_NAME http://127.0.0.1:15435/
ProxyPassReverse /apps/APP_NAME http://127.0.0.1:15435/
You can take a look at this tutorial here on how to configure Apache as a Reverse Proxy with mod_proxy:
Hope that this helps! Regards, Bobby
Hello everyone, just a short update:
Yesterday I saw my error, I could access https://mywebsite.dev:10443 because I was running docker with 0.0.0.0 (which means the docker container was also reachable for outside).
I corrected it by changing to 127.0.0.1 in the docker-compose.yml:
version: "3.7"
services:
db:
image: postgres:alpine
command: -p 5435
environment:
POSTGRES_USER: psgadmin
POSTGRES_PASSWORD: 12345
PG_PORT: 5435
POSTGRES_DB: snippetfy
volumes:
- pgdata:/var/lib/postgresql/data
restart: always
networks:
- app-network
container_name: postgres-db
web:
build: .
depends_on:
- db
ports:
- 127.0.0.1:10443:10443
volumes:
- webapp:/home/node/app
- /home/node/app/node_modules
environment:
DATABASE_URL: ${DATABASE_URL}
NODE_ENV: ${NODE_ENV}
networks:
- app-network
container_name: snippetfy-node
hostname: snippetfy-node
volumes:
pgdata:
webapp:
networks:
app-network:
driver: bridge
Now at least I cannot reach anymore by typing https://mywebsite.dev:10443.
However my problem is still not solved, I do not know what else I can do to make the proxy works correctly and finally access my app(s) through https://mywebsite.dev/apps/app_name.
I am thankful for every help!
Best Regards, Gabriel
Hi @tinieblas ,
thanks for your reply to my post.
I tried what you said but I still get errors and do not really know how to fix it.
Maybe a better idea would be to create subdomains and use them instead of using my portfolio domain to it.
Kind Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.