1

So I have a node server within a docker container. Right now I would like to have it communicate with the parent system's CUP server. However when I do an ajax call to the server, with port 631 exposed I get a 400 bad request error. When looking at the CUPS logs it gives this reason for the rejection:

Request from "localhost" using invalid Host: field "host.docker.internal:631"

Now to even access the parent machine I have to use host.docker.internal to gain access, but I have not figured out a way to get cups to ignore the host or think its localhost.

Cups is watching for any serverAlias, and anything on port 631 so it "should" accept the call. Any ideas?

knightsbore
  • 470
  • 2
  • 8
  • 24
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – Alejandro Teixeira Muñoz Oct 04 '19 at 22:00
  • Check this @knightsbore maybe it can help you. I think the solution will be there https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach – Alejandro Teixeira Muñoz Oct 04 '19 at 22:00

1 Answers1

0

I had the same problem with CUPS (2.3.4) on osx. I spent several hours to fix the invalid Host: field error.

It seems that there's a bug, even when using SeverAlias * on cups conf.

For those who are looking for a workaround: We have to change the Host header sent from the docker container to localhost in order to do so, I managed to set up an Nginx container listening on port 8888 and rewriting the Host field while proxy_pass to the host’s CUPS server.

This is the nginx conf.d:

server {
listen       8888;

location / {
    proxy_pass http://host.docker.internal:631;
    proxy_set_header Host localhost;
}}

Now instead of connecting to host.docker.internal:631 we connect the cups client to localhost:8888. (I have set up the nginx sever on the same docker container, you might want to set up a separate container depending on your needs)