2

I have a little problem with CUPS 2.2.7

This is my /etc/hosts file:

127.0.0.1   example.com

127.0.0.1   localhost

in http://localhost:631/ CUPS is working right

but in http://example.com:631/ it doesn't work on the same pc.

The message error in View error log is that one:

E [21/Feb/2019:11:54:18 +0100] [Client 33] Request from "localhost" using invalid Host: field "example.com:631".

The web page on Firefox print an error message Invalid request and give me an Error (error code: 400) but seems point on CUPS.

How to solve this problem so that example.com:631 points to localhost and CUPS answers it successfully instead of Error 400: Access Denied.

2
  • You would have to pass option to CUPS to allow it to service http request for example.com host. The hostname is passed via http request to the server too, not only ip is important.
    – KamilCuk
    Feb 21, 2019 at 11:59
  • what option should I pass to do it? Feb 21, 2019 at 14:48

2 Answers 2

22

By default cups servers HTTP requests only with HTTP Host header equal to "localhost". To allow it servicing requests for additional HTTP host headers use ServerAlias directive as described in the man cupsd.conf documentation. It's common to do the most unsafe thing and add

ServerAlias *

to /etc/cupsd.conf to allow all possible HTTP host headers to be serviced.

2
  • 1
    That did not work for me. I still get bad request, even after rebooting. Mar 9, 2020 at 12:31
  • 5
    it worked for me in combination to Listen *:631
    – Mayur
    Jun 7, 2021 at 10:58
4

I know this is old, but I too was experiencing the same issue recently and I resolved it by updating the following line in cupsd.conf from:

Listen 0.0.0.0:631

changed to:

Listen *:631

For those that maybe care to know, I'm running CUPS within a docker container, and this change corrects the "Bad Request" response.

1
  • I'm not using Docker, and tried to use your version "Listen *:631", but I'm always having this error [stacktrace=java.io.IOException: HTTP error! Status code: HTTP/1.1 400 Bad Request. This error happen when I try to use this call List<CupsPrinter> printers = cupsClient.getPrinters(); Can you or anyone help with that.
    – Ilya Budu
    Oct 6, 2021 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.