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

265
Visualizações
Nginx with docker, location different from slash not found

Summary

I created this simple example to correct and check the errors that I have in another more complex project. So I've a docker-compose file with 1 web server and 2 app and a nginx conf file.

Please note, that I'm testing it with Docker Quick Start Terminal for Windows 10 Home Edition, but I've tested even on Ubuntu 18.04 and the outcome is the same.

Outcome

Going to: http://192.168.99.100:8080/
Default output:

It works!

The only issue here is with app2, since I'm not able to access app2.

Going to http://192.168.99.100:8080/app2.
Error:

Not Found

The requested URL was not found on this server.

I'm not understanding why I'm not able to do that, and where is the error.

What I've Tried

  • Switch the location order, so location /app2 after location /, but nothing changed
  • Change the location of location /app2 to location /foo, even here same outcome.
  • Change the path related to the previous example, anything different from location / does not works. (e.g. location /bar location /foobar location /test)
  • Change location / in order to refer the app2 instead of app1, and it works but in this way I can't reach app1.

    
    location / {
        proxy_pass http://app2:80;
    }

    location /app1 { proxy_pass http://app1:80; }

Code

docker-compose.yml

version: "3.7"

services:
  web:
    image: nginx:alpine
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    ports:
        - 8080:80
    networks:
        - app1_net
        - app2_net

  app1:
      image: httpd:latest
      networks:
        - app1_net

  app2:
      image: httpd:latest
      networks:
        - app2_net

networks:
  app1_net:
  app2_net:

nginx.conf

events {}
http {
    server{
        listen 80;
        listen [::]:80;

        server_name localhost;

        location /app2 {
            proxy_pass http://app2:80;
        }

        location / {
            proxy_pass http://app1:80;
        }
    }
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

This is the correct way, use a regex to allow sub folders navigation and a perfect match on /app2 to redirect traffic on http://app2:

location ~ ^/app2/(.*)$ {
  proxy_pass http://app2/$1;
}
location = /app2 {
  proxy_pass http://app2/;
}
location / {
  proxy_pass http://app1;
}
over 4 years ago · Santiago Trujillo Relatório

0

I have added another stackoverflow answer here.

It is summarized here:

  • My setup has a couple of apps sitting behind nginx. I want to redirect /appx-uri/bla/blo/bli to /appx-uri/bla/blo/bli/ instead of /bla/blo/bli/ which is the default nginx behavior.
  • Also, all my static files (for an app) are gathered for nginx to serve /repairapp/static/.

Adding the directive rewrite ^/repairapp/([^static].*[^/])$ /repairapp/$1/ permanent; in the server block fixes it.

I then have

  • To fix the issue: rewrite ^/repairapp/([^static].*[^/])$ /repairapp/$1/ permanent;
  • To have nginx serve resources location /repairapp/static/ {
  • To access an app location /repairapp/ {
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