Request to nginx in Docker losing port number in a specific request

by gdbj   Last Updated January 06, 2018 21:00 PM

I'm running Nginx inside Docker, with port mapping 8080:80. My content is mapped to /var/www/content'.

I create the following two files at the following paths:


My nginx.conf is defined as the following:

server {
  server_name _;
  listen 80 default_server;

  root /var/www/content;
  index index.html;

  access_log /dev/stdout;
  error_log /dev/stdout info;

  add_header X-debug-base "base $uri $document_root" always;

  location / {
    add_header X-debug-one "location / $uri $document_root" always;
    try_files $uri $uri/ index.html;

I'm able to execute the html files I put there when accessing it via the following requests:

  1. http://localhost:8080 -> runs first index.html, browser shows http://localhost:8080
  2. http://localhost:8080/ -> runs first index.html, browser shows http://localhost:8080 (why is the trailing slash stripped here?)
  3. http://localhost:8080/index.html -> runs first index.html, browser shows http://localhost:8080/index.html
  4. http://localhost:8080/test/index.html -> runs test/index.html, browser shows http://localhost:8080/test/index.html
  5. http://localhost:8080/test/ -> runs test/index.html, browser shows http://localhost:8080/test/
  6. http://localhost:8080/test -> FAILS. Browser shows http://localhost/test/, which errors out due to losing the correct port.

Two mysteries for me:

1) Why is the trailing slash stripped on Test Case #2, and who is responsible for it? Ie: is that Chrome or Nginx?

2) More relevant to my question, is Test Case 6. Why am I losing the port number on only this kind of request? When testing for other words that don't match to a folder on my local, the request is handled as expected.

I searched on how to trace through the execution of nginx, but it seems very difficult to do. The headers idea below doesn't help, and the log has nothing in it that is helpful either.

How can I figure out the culprit for rewriting my URL?

Tags : nginx docker

Related Questions

Browser services' container in Docker Swarm mode

Updated April 26, 2017 08:00 AM

How to make AWS containers communicate

Updated January 02, 2018 23:00 PM

Docker Nginx reverse proxy configuration

Updated May 08, 2018 23:00 PM