HTTP code is always 301 when used behind nginx-proxy
domenix opened this issue · comments
Quite handy project, but I think there is a small issue.
When I am defining a container behind an nginx-proxy, and I try to query the source domain using curl -i subdomain.owndomain.com
the message is always: 301 Moved Permanently
, no matter what redirect code do I define.
301 code
example@PC:/mnt/c$ curl -i subdomain.owndomain.com
HTTP/1.1 301 Moved Permanently
Date: Mon, 02 Aug 2021 23:57:45 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Location: https://subdomain.owndomain.com/
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=<redacted>"}],"group":"cf-nel","max_age":604800}
NEL: {"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 678xxxxxxxxxxxx4-OTP
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
See below an example docker-compose file which is an excerpt from my configuration.
docker-compose.yaml
version: '3.8'
services:
nginx-proxy:
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
ports:
- 80:80
- 443:443
volumes:
- conf:/etc/nginx/conf.d
- certs:/etc/nginx/certs:ro
- vhost:/etc/nginx/vhost.d
- dhparam:/etc/nginx/dhparam
- html:/usr/share/nginx/html
- /dev/urandom:/dev/random
- /var/run/docker.sock:/tmp/docker.sock:ro
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
restart: always
nginx-proxy-acme:
image: nginxproxy/acme-companion
container_name: nginx-proxy-acme
depends_on:
- nginx-proxy
volumes:
- certs:/etc/nginx/certs
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- acme:/etc/acme.sh
- /dev/urandom:/dev/random
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
restart: always
example_redirect:
image: adamkdean/redirect
container_name: example_redirect
volumes:
- /dev/urandom:/dev/random
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- VIRTUAL_HOST=subdomain.owndomain.com
- REDIRECT_LOCATION="https://example.com"
- REDIRECT_STATUS_CODE=302
restart: always
volumes:
conf:
vhost:
html:
dhparam:
certs:
acme:
networks:
default:
external: true
name: nginx-proxy
Thanks for the report, I'll take a look into this when I get a moment
FYI: When running in a 3 container setup the headers are correctly send.
Thanks @rutger1140. I haven't had chance to work on this yet but if anyone wants to contribute a PR I'll be happy to review and merge.
cc @domenix
@rutger1140 yep, all sorted. Sorry for the delay in this, and thank you!
@rutger1140 v1.2.4 pushed to docker hub FYI
@rutger1140 yep, all sorted. Sorry for the delay in this, and thank you!
Happy to help!