Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

481
Views
Traefik - proxy to backend for angular application

I have set up a proxy with Nginx which is as follows

    server {
       listen       80;
       server_name  localhost;

       location /api {
          proxy_pass https://api.mydomain.com/;
       }

       location / {
         root   /usr/share/nginx/html;
         index  index.html index.htm;      
       }

       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
          root   /usr/share/nginx/html;
       }
    }

my Dockerfile

       FROM node:12-alpine as builder
       WORKDIR /workspace
       COPY ./package.json ./
       RUN npm install
       COPY . .
      RUN npm run build

      FROM nginx
      COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
      COPY --from=builder /app/www /usr/share/nginx/html
      EXPOSE 80
      CMD ["nginx", "-g", "daemon off;"]

This works fine But wants to replace Nginx with Traefik for the above proxy settings. Any help would be much appreciated since I'm very new to traefik.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

With Traefik 2+, you need to configure 2 routers: - One for the API - One for the webapp

For the API proxy, you will have a rule like:

rule = "Host(`example.com`) && Path(`/api`)"

And the webapp will juste have the host as rule

rule = "Host(`example.com`)"

For kubernetes, you can do it in an ingress like that:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: simpleingressroute
  namespace: default
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`example.com`) && PathPrefix(`/api`)
    kind: Rule
    services:
    - name: mywebapp-svc
      port: 80
  - match: Host(`example.com`)
    Kind: Rule
    services:
    - name: myapi-svc
      port: 80

If the API is not inside the kubernetes cluster, you can define the rule tu use an externalService like that:

---
apiVersion: v1
kind: Service
metadata:
  name: myapi-svc
  namespace: default
spec:
  externalName: api.mydomain.com
  type: ExternalName
over 4 years ago · Santiago Trujillo Report

0

if you want to step up from that manual configuration, you may use Traefik as described here. Watch how he uses docker labels to define how to route HTTP traffic. I personally use caddy docker proxy in docker (swarm, but not required) which I find easier to understand and use

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!