Traefik/Docker/Wildfly - Cannot access Wildfly management console - docker

I'm running Traefik in a Docker container, with Wildfly in other container.
I have the following labels in Wildfly's docker-compose.yml:
- "traefik.web.port=8080"
- "traefik.web.frontend.rule=Host:temporary_wildfly_hostname"
- "traefik.admin.port=9990"
- "traefik.admin.frontend.rule=Host:temporary_wildfly_hostname;PathStrip:/console/"
I can access the main Wildfly, which is in port 8080. I've tried many ways to access the service in port 9990, but the only one which really works is when I use a different Host, which isn't what I want.
I've tried:
Added "traefik.frontend.passHostHeader=true" (even with .admin before .frontend)
Switching PathStrip with PathPrefixStrip, Path PathStripRegex or even PathPrefixStripRegex
Wildfly's management console uses port 9990, redirects from :8080/console and also uses :9990/console/*, so /console by itself is redundant and it shows "too many redirects" errors.
I really think this /console loop error is some kind of an issue. I've been searching online for alternative configurations for other reverse proxies, to see if I'm missing something, but all relate to the headers, which I've already tried.
Any hint on how can I solve this, keeping the same URL, but still redirecting to a different port than the main service?
Thanks a lot for your time and help.
Best regards,
Luis Nabais

You need to add a priority on each segment.
traefik.<segment_name>.frontend.priority=10

Thanks a lot for your answer.
The issue was related to the backend wildfly creates. It uses another URL, which is /management. So I solved it using the following traefik labels:
- "traefik.web.port=8080"
- "traefik.web.frontend.rule=Host:temporary_wildfly_hostname"
- "traefik.admin.port=9990"
- "traefik.admin.frontend.rule=Host:temporary_wildfly_hostname;PathPrefix:/console,/management"

Related

CORS Fastapi Problem in dockerized deployment to Digital Ocean

I have deployed my first webapp at a digital ocean droplet.
The app has two docker containers running at :8000 and :5173
It has a frontend and a backend.
Originally I thought Cors is not enabled.
However after more research I think the issue lies with Fastapi as I've found other threads with similar problems.
Unfortunately none worked. There is talk on github and SO that fastapi and docker is the problem, but it works fine on my local machine. (in the container).
I tried these, this and pretty much everything I could find.
The error message is:
Access to fetch at 'http://<IP address>:8000/mdstats_player' from origin 'http://<IP address>:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
GET http://<ip_address>/mdstats_player net::ERR_FAILED 200
In Fastapi I set up the allowed origins including that new IP address.
Exactly like https://fastapi.tiangolo.com/tutorial/cors/ and it works locally originally getting the same error.
I also tried the wildcard and starlette.
I can access http://<ip_address>:8000 just fine.The container is running as expected.
On my local machine everything works as expected too. (i.e. backend and frontend containers can communicate).
The origins I set, (where ipaddress is my Digital Ocean IP address), the exact same one that gets denied, I think I have all variations, but maybe I am missing one?
origins = [
"http://localhost:5173",
"localhost:5173",
"http://<ip_address>:5173",
"<ip_address>:5173",
"http://<ip_address>:5173/",
"localhost:5173/",
"0.0.0.0:5173",
"http://172.18.0.2:5173/",
]
As a last chance:
I am also using svelte with vite.
In my docker-compose file I set:
- VITE_BACKEND_URL=http://<ip_address>:8000
original set to localhost
Many thanks in advance.
After trying pretty much everything I have found a solution:
instead of adding the middleware afterwards like they do on the fastapi tutorial
I did this:
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware import Middleware
app = FastAPI(middleware=middleware)
origins = [
"http://localhost:5173",
"http://localhost:5173/",
"localhost:5173",
"localhost:5173/",
"0.0.0.0:5173",
"http://172.18.0.2:5173/",
"http://192.168.64.2:5173/",
]
middleware = [
Middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']
)
]
I also had to add the network ips.
But the middleware part was crucial. Even with the network ips with app.add_middle_ware this won't work. I tried several times just to make sure that really is the solution since it seems like a lot of the other posts that come across have solutions that were just along the way since docker doesn't update everything each system update. See issues of docker on github.
Hope this helps someone. What insanity.

Terraform - self.default_ip_address / ipv4_address missmatch

I have some annoying problem here.
I am trying to use file and remote-exec provisioners when creating (Windows) VM-s with Terraform.
Please see my template (this is only for a VM, I separated it from the variables and the core infrastructure for now) here: https://code.prkr.li/60463d5e2b38ad032b4b6678
The only thing that does not work presently is using the self.default_ip_address as a host for the provisioner's connection. The task (as seen in the Terraform logs in Jenkins) tries to connect to the IP address that the VM got from DHCP...
...instead of what is defined in the (customization) config...
So I suppose viable solutions would be:
refreshing the default IP
using hostname (not sure if that is possible, did not manage to find the right syntax)
???
Any ideas / suggestion please?
Not that there were a lot of answers, but I found my solution apparently.
Anyone having similar issue, suggested to use
host = self.clone.0.customize.0.network_interface.0.ipv4_address
Workes for me anyway.

Add a URL path prefix to artifactory installation (Docker)

I'm running Artifactory CPP CE 7.7.3 and Traefik v2.2 using docker-compose. The service is only available over http://localhost/ui/. Now, what I need is an option which allows to add a URL path-prefix (e. g. http://localhost/artifactroy/ui).
My Setup
I used the described setup process from the Artifactory Docs suggest it.
My docker.compose.yaml is the official extracted from the jfrog-artifactory-cpp-ce-7.7.3-compose.tar.gz: ./templates/docker-compose.yaml.
I'm using a reverse proxy (traefik). For this, I've added the necessary traefik configuration lines to the docker-compose-file. Here is a small extract what I've added:
[...]
labels:
- "traefik.http.routers.artifactory.rule=Host(`localhost`) && PathPrefix(`/ui`)"
- "traefik.http.routers.artifactory.middlewares=artifactory-stripprefix"
- "traefik.http.middlewares.artifactory-stripprefix.stripprefix.prefixes=/"
- "traefik.http.services.artifactory.loadbalancer.server.port=8082"
With this I managed to access artifactory over http://localhost/ui/.
Problem:
I have multiple small services running on my server, each of this service is accusable via http://localhost/<service-name>. This is very convenient and want to make clear that this URL is related to this service on my production server.
Because of this, I want to have an URL like http://localhost/artifactroy/ui/... instead of http://localhost/ui/...
I struggled getting artifactory setup in that way. I already managed to get a redirection from typing e. g. http://localhost/artifactroy/ to http://localhost/ui/ but this is not what I want on my production server.
What I did
Went through the documentation in hope of finding an option which I just can passt to artifactroy to add a prefix (Not successful).
Tried configure traefik two full days, to alter headers to get the repose point to http://localhost/artifactroy/ui/... (Only partially successful, redirection didn’t work afterwards)
Tried finding the configuration which is responsible for configure artifactory in $JFROG_HOME/artifactory/var/etc (Not successful)
Is this even possible? Help is highly appreciated..
This example (even though not traefic example) gives you a direction to implement it. There are certain routes already used within the product. You need to add a context over and above it to ensure all comes via the new context path.
https://jfrog.com/knowledge-base/how-to-remove-artifactory-from-the-context-url-in-artifactory-7/

My rack-proxy app works with different ports, but not different URLs

I wrote a little Rack app the uses rack-proxy to make it look like apps that are running on different ports are actually different subdirectories of one domain. It works.
If I'm running notes on port 3001 and photos on 3002, then I'm able to go to localhost:3000/notes or localhost:3000/photos and everything works properly.
That's only helpful for running it locally. But if I want to run this same setup on Heroku I need to be able to proxy to/from different URLs, not just different ports. So when I change my code from setting env["HTTP_HOST"] to http://localhost:3001 for /notes, to instead set env["HTTP_HOST"] to http://sbbme-note.herokuapp.com for /notes, Rack blows up on me.
I thought it would Just Work™. Unfortuntely, I'm missing something.
Errno::EADDRNOTAVAIL at /notes
Can't assign requested address - connect(2) for "http://sbbme-note.herokuapp.com" port 0
The full stack trace is in this gist.
https://gist.github.com/veganstraightedge/6d840377bf20b4b5f5db
The repo is homesteading/homesteading-router-rack. The master branch is the one working in local development mode only (multiple ports on localhost). The heroku-router branch is where I'm trying to use different (sub)domains instead of just different ports. heroku-router is the one that blows up (see gist above).
If you want to install this and try it on your own machine, this should work:
gem install homesteading
homesteading new mysite
cd mysite
homesteading server
open http://localhost:3000
I'm real close to being able to replace my years old pile of mono-rails with my constellation of apps approach in Homesteading. This router is the last main blocker. Any help would be greatly appreciated.
PS. My intial version is based on this blog post (livsey dot org/blog/2012/02/23/using-rack-proxy-to-serve-multiple-rails-apps-from-the-same-domain-and-port) and this Stack Overflow question/answer (stackoverflow dot com/questions/11057905/how-do-i-use-rackproxy-within-rails-to-proxy-requests-to-a-specific-path-to-an "How do I use Rack::Proxy within Rails to proxy requests to a specific path to another app - Stack Overflow").
Looking at the setup and the stack trace it looks like the proxy is atrying to connect to the sbbme-note app on port 0. Try adding
ENV['SERVER_PORT'] = '80'
You might also consider using the nginx build pack on heroku an implementing a forward proxy that way. I've used this build pack as a basic forward proxy and it has worked great. There are other nginx build packs that are designed to hook up to you application server (like unicorn) that might also be useful for this use.
The solution was a combination of Lukas' suggestion and fixing what I was originally doing.
I added this (as suggested by Lukas).
env['SERVER_PORT'] = 80
AND I removed the http:// from my env["HTTP_HOST"]
So, this:
env["HTTP_HOST"] = "http://#{app}"
became this:
env["HTTP_HOST"] = app
Thanks for your help, Lukas!

MVCSiteMap Port Problem

I am using MVCSiteMap - http://mvcsitemap.codeplex.com/ - with Azure and I am trying to figure out how I can get it to remove the PORT number at the end of the generated sitemap.
Currently, I am getting
http://127.0.0.1:5100/
For this url and all others. Does anyone have any experience with this or know how to remove the port no ?
If you run your code on production (something.cloudapp.net), this port number should dissappear.

Resources