0

I'm following the example docker compose for an nginx-proxy, but it always returns a 301 Moved Permanently error. I'm using docker hosted in Ubuntu 22.04.

my docker-compose.yml file

version: '2'

services:
  nginx-proxy:
    image: nginxproxy/nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ../certificates:/etc/nginx/certs:ro
    depends_on:
      - whoami

  whoami:
    image: jwilder/whoami
    expose:
      - "8000"
    environment:
      - VIRTUAL_HOST=whoami.media.local
      - VIRTUAL_PORT=8000

my test command and output:

user@media:~/docker/nginx-test$ curl -H "Host: whoami.media.local" media.local
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.25.1</center>
</body>
</html>

output from the nginx log

nginx-proxy_1  | nginx.1     | whoami.media.local 192.168.0.2 - - [11/Aug/2023:16:57:07 +0000] "GET / HTTP/1.1" 301 169 "-" "curl/7.81.0" "-"

I've tried adding 192.168.0.2 whoami.media.local to my host's /etc/hosts file and the result is the same:

user@media:~/docker/nginx-test$ curl -I whoami.media.local
HTTP/1.1 301 Moved Permanently
Server: nginx/1.25.1
Date: Fri, 11 Aug 2023 17:00:57 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://whoami.media.local/

per the website example, the expected output is: I'm 5b129ab83266

What am I getting wrong in my system configuration?

PaulH
  • 181
  • 1
  • 3
  • 8
  • You've taken the working example and associated test command, made modifications to the docker-compose but kept the test command. Have you tried the basic example without editing anything and then started editing to see where you went wrong? Your `curl -I` looks pretty clear to me. – Ginnungagap Aug 11 '23 at 17:22
  • my only change of consequence was to update the VIRTUAL_HOST parameter to match my system. I can remove the port 443, certificate directory, and dependency and the result is the same. – PaulH Aug 11 '23 at 17:26
  • 1
    Surprising given the block in which the redirection to https occurs in the [nginx configuration template](https://github.com/nginx-proxy/nginx-proxy/blob/main/nginx.tmpl#L541). – Ginnungagap Aug 11 '23 at 17:33
  • Are you saying that even without exposing certificates the `cert_ok` condition is true? – Ginnungagap Aug 11 '23 at 17:34
  • that's a compelling point... I'll re-verify my assumptions. – PaulH Aug 11 '23 at 17:38
  • you were correct. it was the cert modifications I made combined with bad assumptions. thank you for your help. – PaulH Aug 11 '23 at 17:42

1 Answers1

0

It is possible your issue is that nginx-proxy is redirecting to HTTPS, but you haven't set up SSL for whoami.media.local.

Possible Solutions:

  1. Add SSL: Ensure SSL certificates for whoami.media.local are in the ../certificates directory.
  2. Disable HTTPS Redirect: Add HTTPS_METHOD=noredirect to the nginx-proxy environment in your docker-compose.yml.
yaml
nginx-proxy:
  ...
  environment:
    - HTTPS_METHOD=noredirect
  1. Restart: After changes, run:
bash
docker-compose down
docker-compose up -d
  1. Test:
bash
curl -H "Host: whoami.media.local" media.local

This should resolve the 301 Moved Permanently issue.

suchislife
  • 356
  • 4
  • 11