Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

482
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda