Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda