Valian / docker-nginx-auto-ssl

Docker image for automatic generation of SSL certs using Let's encrypt and Open Resty
https://hub.docker.com/r/valian/docker-nginx-auto-ssl/
MIT License
411 stars 103 forks source link

Parameter for host header #14

Closed davizucon closed 5 years ago

davizucon commented 5 years ago

Is it possible to add host header as boolean (enable/disable) parameter ?

Valian commented 5 years ago

@davizucon what you have exactly in mind? Do you need a X-Forwarded-Host header?

davizucon commented 5 years ago

Yes !

Valian commented 5 years ago

I can add it by default. It's the de-facto standard I believe :)

davizucon commented 5 years ago

Hi @Valian , something like that: Now I need to call thru docker nginx-ssl passing Host: curl --header 'Host: www.example.com' 'http://10.1.1.36:8000/the_url_to_test' if its possible call direct, eg: curl --verbose 'http://10.1.1.36:8000/the_url_to_test'

Thanks!

Valian commented 5 years ago

@PabloZaiden I've just checked, X-Forwarded-For and others X-Forwarded headers are present in configuration - https://github.com/Valian/docker-nginx-auto-ssl/blob/master/snippets/server-proxy.conf.

About your example, I'm not sure if I understand it correctly. Assuming that your domain is xyz.com and everything is set up properly, why you're trying to access IP address, instead of a domain?

For example

# instead of 
curl --header 'Host: www.example.com' 'http://10.1.1.36:8000/the_url_to_test'

# why not to simply use 
curl https://www.example.com/the_url_to_test

We can't disable Host header as you asked, because it's required by NGINX to prepare a SSL certificate, without it it's impossible to find out what domain is used. Also, it's used to figure out which backend server should be chosen for a given request.

davizucon commented 5 years ago

I see, check if you can help me: I need to access directly (by IP) for local tests only, the application behind SSL need host header and SSL set to work. I launch several docker stacks, for every stack I need to set new IP/Domain in /etc/hosts, if nginx set Host parameter in http header, will help me a lot ! I launch on only one domain per docker(docker-nginx-auto-ssl) instead multiple domains.

Valian commented 5 years ago

You shouldn't have to use SSL or even nginx during development. Most applications work fine without it on your local machine.

The way I'm doing this - I have separate docker-compose files for development and production, for example docker-compose.yml for dev and docker-compose.prod.yml for production, and nginx is only in the last one. Probably your application can be configured to work without SSL in development.

But if it's not the case, please try to properly use X-Forwarded-Host, it's the value you're looking for - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host. I'm not sure if I can help you further with this issue, so soon I'll close it.

davizucon commented 5 years ago

You shouldn't have to use SSL or even nginx during development. Most applications work fine without it on your local machine. The way I'm doing this - I have separate docker-compose files for development and production, for example docker-compose.yml for dev and docker-compose.prod.yml for production, and nginx is only in the last one. Probably your application can be configured to work without SSL in development.

It's not the case, if I can choose use or not use SSL my life should be easer :).The application requires SSL, it's not under my control to use or not SSL.

please try to properly use X-Forwarded-Host

I can't change the application behavior.

I'm not sure if I can help you further with this issue, so soon I'll close it.

No problem , I'll fork it, try my self. Thanks for your time and help !!!