I'm using Traefik to manage several Laravel/Wordpress/... apps in a docker environment. Traefik is running in it's own docker container and is used to gain access to my various apps via HTTPS. All of which works fine - probably plenty of room for improvement if an expert were to look at it but I'm happy that it works.
Most apps work with only one domain, but one app in fact uses 8 different domains. So basically we have one default domain (let's say foo.local) which I currently have set up and which works, and also a list of "support" domains which are used in certain situations (e.g. bar.local, foo-status.local, bar-status.local,...). The app takes care of how all of these domains are handled, meaning which information is to be shown to the user etc. My problem is: I don't know how to set it up so that Traefik knows that my app can support all of these domains.
Below is my current docker-compose file for the app. When I do it like this, the default domain still works but I get a 404 nginx error page on the new domain. Aside from the file below, I also updated the laravel.conf file mentioned there to include all of the domains. All virtual hosts are identical except for the URL, for obvious reasons. They all point to the same root directory (app/public in my case, because Laravel wants it that way). If you'd like me to include that here, be sure to let me know. I doubt the error is in there though.
@cakiwi Thanks for your reply. I would love for it to be that easy but sadly this is not the case. I still get the same 404 error. I tried it with and without the additional routers and middlewares but the result is always the same.
Also, so far I've always done docker-compose stop instead of docker-compose down, I don't think that would make a difference but I thought I would mention it to be sure.
Not particularly... Honestly I'm fairly new and inexperienced in Traefik and I just followed a convoluted list of different tutorials to get where I am today and I'm very much aware that there is plenty of room for improvement.
In any case, I tried removing the line but it makes no difference. Still the 404 errors as before.
The multihost rule definitely 'works' the issue could be in the middlewares, header, your backend service of some combination.
#1 First I would recommend using the traefik accesslog to first ensure your router is handling the request. #2 Next make the router as simple as possible and then add middlewares, etc.
So a couple of questions here, do you need all those entrypoints (or routes) to redirect to the same backend?
If using curl to debug (curl -v) are all the endpoints reachable without going through the reverse proxy?
I'm probably old school here but I write my rules like:
"traefik.http.routers.foo-secure.rule="(Host(bar.local) || Host(foo-status.local))"
Not that is related to 404 -- are all your ssl certs generated to have the foo-status.local, bar-status.local on them within the SAN field?
Also your networks. For my network definition (for internal networks or networks defined within the docker-compose file), I usually do the following (you can change docker-net to the name you want, this is example):
This was the first thing that I tried but doesn't work for me. Gives me a 404 error page, not even an nginx page. So my guess is that nginx even fails to start if I do it like this
I doubt it. It's been so long since I did that so I have no idea. Honestly, I just accept the "invalid certificate" warnings on my app and move on, so I doubt this has anything to do with it - I could be wrong
What's the impact of doing it like this? I got this from one of the tutorials I followed and it seems to work just fine, so not sure if this has anything to do with the problem?
Additional info: I just found out that the foo-status.local/something-here returns an nginx error page whereas the foo-status.local page returns the default "Welcome to Nginx" message, which implies that the route is "accepted" but isn't routed to my app, for some reason. I confirmed this by placing a die() statement in my index.php, it was never reached. Does nginx have a problem with placing multiple vhost definitions in a single file?
I don't think nginx has a problem with that although I usually place in different files but I'm aware all the files are concatenated together eventually. I'm not saying traefik is working but it looks like there also might some misconfiguration of the backend as well.
as suggested by @cakiwi was indeed the solution to my problem. In addition to that, the nginx config needed to be modified to include all urls into a single vhost as mentioned below.
server {
server_name foo.local foo-status.local bar-status.local;
root /app/public;
# More config stuff here
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}