VueJS router history mode with Traefik - traefik

I need to do rewrite a URL of my application like this: https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
I'm using Traefik as a reverse proxy and Docker Compose.
Here is my raw configuration in Docker:
application:
build: ./domain.app
volumes:
- ./domain.app/dist:/app
networks:
- net
labels:
- "traefik.frontend.rule=Host:domain.me"
- "traefik.port=8081"
- "traefik.backend=domain.me"
- "traefik.frontend.entryPoints=http,https"
With that configuration:
https://domain.me is working
https://domain.me/anything returns 404
How can I fix this rewrite rule?

For vue.js router history mode you want to catch all Routes that do not point to a resource on the server and forward them to your index.html. For Example:
https://example.com --> /index.html
https://example.com/route/to/subsite --> /index.html
But you still want to be able to access resources that are on the server. E.g.:
https://example.com/path/to/kitten.jpg --> /path/to/kitten.jpg not /index.html
In order to do that you have to find a Backend Server supporting Catch-All Fallback. You can use the ones noted in the vue.js Guide (Apache, Nginx, Node, IIS)
Why can't I use traefik for this?
As stated above you still want to be able to serve static resources. But traefik is just a router. It does only has access to the information of the request, not to the information of the server. But in order to decide if to serve the index.html or the static resource you must have access to the resources.
You could route all the traffic to the index.html using Traefik's PathPrefixStripRegex:but this would result in serving index.html for every request, even if you would have wanted kitten.jpg.

Related

Netscalar redirect request to OpenShift route

Currently we have a C# web api running on 2 IIS servers, We are using Netscalar to load balance between IIS1 and IIS2 servers.
We have containerized our API and deployed it to OpenShift, as part of our testing initially we would like to point OpenShift as third node.
Means Netscalar should forward the request to OpenShift route also.
How can this be achieved in Netscalar.
My OpenShift route name is different so we tried specifying URL transformation rule to redirect IIS incoming request to OpenShift exposed route, but we are facing 503 service unavailable error.
What is the right way of configuring Netscalar to my API request are handled between IIS1, IIS2 and OpenShift ?
I don't think in most cases URL transformation is necessary. In a Route you can specify any host that you would like, so you can use your old DNS name. When a request with that HTTP Host header arrives at the OpenShift cluster (specifically at any Router Pod) it will be forwarded to your application.
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: my-route
...
spec:
host: www.example.com
...
Your Netscaler load balancer needs to forward the traffic to the OpenShift Load Balancer (which is typically a separate IP), which in turn will forward it to the Router Pods.

HTTPS redirect traefik v2

I'm trying to setup traefik v2 on a development server we have.
The setup:
Docker serving dozens of nginx containers acting as a frontend for different projects. Every nginx container has a unique domain linked to it. Nginx is running on port 80. Every project has a separate docker-compose (traefik also has a separate docker-compose).
What I'm trying to accomplish:
Proxy all of the containers to traefik and add new ones on the go (new services are stopped/started all the time). Make traefik automatically redirect to HTTPS and contact the appropriate nginx container based on the hostname in order to serve the website.
Question: Is this even possible to do? I've been trying to figure it out for the past day or so but I can't get everything to work. Either the redirect doesn't work or if it does it returns 404.
Managed to find a guide that covers this:
https://chriswiegman.com/2019/10/serving-your-docker-apps-with-https-and-traefik-2/
To extend what the guide pointed to, the magic sauce is in LABELS. It can be broken down to this:
# Setup HTTP
# tells traefik that cany HTTP connection needs to be re-directed to HTTPS
- "traefik.http.middlewares.mysite-https.redirectscheme.scheme=https"
# 'web' (or any name) can be defined my traefik entrypoints. Web is port 80.
- "traefik.http.routers.mysite-http.entrypoints=web"
# tells to route incoming connections to 'mysitesdomain.com' to this service
- "traefik.http.routers.mysite-http.rule=Host(`mysitesdomain.com`)"
# Maps the above 'middleware' called 'mysite-https'
- "traefik.http.routers.mysite-http.middlewares=mysite-https#docker"
# Setup HTTPS
- "traefik.http.routers.mysite.entrypoints=web-secure"
- "traefik.http.routers.mysite.rule=Host(`mysitesdomain.com`)"
- "traefik.http.routers.mysite.tls=true"
- "traefik.http.routers.mysite.tls.certresolver=default"
What seems to be missing the loadbalancer definition.
- "traefik.http.services.replica_service.loadbalancer.server.port=80" # "80" is the container's incoming port.

How can I redirect subdomain.mydomain.com to subdomain.mydomain.com/path/subpath

I am utilizing traefik through docker labels.
I have a container that has both kibana and elasticsearch and I would like to have frontend rules for both of them. I was able to do this by following this PR, but I ran into an issue of Kibana no longer redirecting /app/kibana with the subdomain.
My labels are as follows:
traefik.enable=true
traefik.frontend.redirect.entryPoint=https
traefik.elasticsearch.frontend.rule=Host:elasticsearch.mydomain.com
traefik.elasticsearch.port=9200
traefik.kibana.frontend.rule=Host:kibana.mydomain.com
traefik.kibana.port=5601
To clarifiy, previously when I navigated to mydomain.com:5601, I would be redirected to mydomain.com:5601/app/kibana. I would like this functionality back while still utilizing the subdomain.

traefik - Route Path to root context host.com/mailcatcher - > container/

I'm trying to host mailcatcher in docker swarm and serve it with Traefik. I'm running mailcatcher as a service which unfortunately hosts itself on the / root context path like localhost:10980/. I have a frontend rule /mailcatcher with PathPrefixStrip so the initial load works but then the app tries to reach host.com/assets which obviously doesn't exists. Does traefik has any solution like the sub_filter option in nginx to route these requests or do I have to add these as a frontend rule to be able to host it?
Thanks in advance

HA Proxy rule - 404 not found

I have configured below rule in HA Proxy. I get 404 not found when I try to hit http://haproxy_ip/service
frontend http-in
bind 10.254.23.225:80
acl has_service path_beg /service
use_backend service_server if has_service
backend service_server
balance roundrobin
cookie SERVERID insert
option httpchk HEAD /check.txt HTTP/1.0
option httpclose
option forwardfor
server server1 192.168.2.1:9000 cookie server1 check
backend doesnt have /service in itself. I use haproxy to have virutal path in url.
With the current configuration, /service/test.txt will trigger the acl has_service and will send /service/test.txt to your backend, without changing the url.
If you want to change the url (proxying /service in the frontend to / in the backend), you should add the following line in your backend:
reqrep ^([^\ ]*)\ /service(.*) \1\ \2
This will remove /service from the proxied request.
Edit:
HAProxy won't rewrite the html output: your assets won't get a leading /service/ and won't be served correctly.
When you proxy requests, it is way easier to keep the same path: proxying / to / or /myapp/ to /myapp/ for example. If you proxy /a to /b/c, the proxy itself will need to rewrite the response: <img src="/a/test.png"> needs to be changed to <img src="/b/c/test.png">. Or worse, <img src="../c/test.png" />. Add relative references in html, js and css too. I'm not sure it's doable with HAProxy.
If you can change the application and deploy it on /service/, you will avoid a lot of issues. Using an other vhost (service.yourdomain.com for example) can solve this issue too.
If not, I'm not sure HAProxy is the right tool here, I'd try apache 2.4 with
mod_proxy_html (but not before trying really hard to deploy the app on /service/).