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

266
Views
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 answers
Answer question

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 Report

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 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!