Is it possible to create a route for an apache/php dameon on the host?

I have a server running cpanel with apache and php/fpm. fpm is using nginx right now as a reverse proxy.
I am adding a few docker apps on the server and I'd like to tie them all together with Traefik.

Can I have Traefik route like so:

  • request: http://mydomain.com/my_php_app

  • routes to my existing apache/php/cpanel install on the server
    I know I can spin up an apache container and mount my php app inside, but I want to use my existing cpanel setup that sits on the machine itself.

  • request http://mydomain.com/my_dockerized_app

  • routes to: whichever dockerized app traefik is configured for

I can't find any docs on how to connect to a service like httpd thats on the machine and not in a container.
Can this be done?

Yes, use a file provider and use the address of the docker0 interface as the target url.

I was looking at the http provider. Hadn't considered using file.

Thanks!

1 Like

I'm still trying to figure out how to have some domains route the traffic to the bare metal nginx->httpd service. I've added docker0 and enabled docker in the csf firewall file, but I'm not seeing how putting the docker interface in a file provider connects it together.

I'm working on a workaround where I'm just spinning up an nginx docker container and simply doing a mount like -v /etc/nginx:/etc/nginx. This way it's loading all the cpanel and other config files for my bare metal nginx.. It's somewhat working but I still have to match the container version to the bare metal version and probably tweak a few more things.

I'm just hoping I can figure out how to let cpanel/apache handle some of my endpoints and my containers handle the other domains I have.

It can be any host ip, this one can be the easiest. The traefik container can only address the networks it is connected to or use its default gw.

Here is an eample:

# docker-compose.yaml
version: '3.8'
services:
  traefik:
    image: traefik:v2.4
    ports:
      - '80:80'
    command:
      - --entrypoints.http.address=:80
      - --api=true
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --providers.file.directory=/conf
      - --accesslog=true
      - --log.level=DEBUG
    labels:
      traefik.enable: true
      traefik.http.routers.api.rule: host(`traefik.localhost`)
      traefik.http.routers.api.service: api@internal
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./dynamic:/conf/"
  one:
    image: traefik/whoami
    command:
    - --name=docker
    labels:
      traefik.enable: true
      traefik.http.routers.one.rule: host(`app.localhost`) && PathPrefix(`/docker`)

# dynamic/dynamic.yaml
http:
  routers:
    two:
      rule: Host(`app.localhost`) && PathPrefix(`/notdocker`)
      service: two
  services:
    two:
      loadBalancer:
        servers:
        - url: http://172.17.0.1:8888
# run whoami on port 8888
./whoami -port 8888 -name notdocker
1 Like

Thanks for providing some example code. Now I understand better what you mean.
I think what I'm trying to do is different.
I have a remote webserver I've had for years running cpanel/nginx/apache/php-fpm/mysql on the metal. For my old domains, I'd like to have those requests go to my bare metal lamp stack so I don't have to build containers for my old domains. Somehow Traefik would have to take the request and if see's that it is an 'old' domain, hand that request over to the bare metal nginx and have nginx take it from there.
If Traefik sees a 'new' domain it will route those through my containers and not the bare metal lamp stack. It would look something like this:

===========================================|====== bare metal services===
-> request: old-domain.com --> traefik:80 -|-> nginx:81 --> apache:82`
===========================================|====== bare metal services===


===========================================|====== docker services===
-> request: new-domain.com --> traefik:80 -|-> docker services
===========================================|====== docker services===

The closest I've been so far is:

  • disable bare metal nginx
  • run nginx:latest
  • map volume /etc/nginx:/etc/nginx to apply bare metal config files to the container. This way the container is behaving like the bare metal nginx

It works for html files, but somethings wrong with php as php pages give a 302 and prompt the browser to download. It also seems like a clunky solution.

I suppose I can change the A record on the old domains to point to a seperate ip address where I can have both bare metal nginx AND traefik on port 80/443.

It would be cool to be able to do it with Traefik tho.

Related thread about this challenge
https://forums.c panel.net/threads/traefik-setup-on-whm.676385/

I guess I'm missing something. Possibly more to the nginx config making it different.

In the example traefik routes 'old' (in this case a path prefix but can be any rule) to bare metal (represented by whoami on port 8888)

And routes new to docker services.

I think this bit is what I've been looking for.

My config is now setting the ForwardURL to the value of two.loadBalance.servers.url and that seems to be doing the proxy to load the target endpoint (in my case my bare metal nginx instance) Instead of timeout errors, at least now I'm getting Bad Gateway so it seems to be trying to connect. I'm on Laragoon which is like xampp so I'm sure its a matter of playing with the network settings to get everything connected.

I followed docker-heavy walkthroughs on Traefik setup and for some reason I could only think of endpoints being docker containers. That led me wayyy into left field. I figured there should be a basic way to redirect filtered traffic to any endpoint and not just docker containers. I think I can figure it out from here. Thanks again!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.