apache reverse proxy with SSL gives '400 bad request'

14,839

Solution 1

I actually fixed it using the below modifications.

ServerName MySite

is changed to

ServerName example.com:8069

And

ProxyPass / http://localhost:9069/
ProxyPassReverse / http://localhost:9069/

is changed to

ProxyPass / http://localhost:9069/
ProxyPassReverse / http://example.com:8069/

Solution 2

I see this is months old and stumbled on it after a search. In case this is helpful to future searchers...

I do something similar with a reverse-proxy configuration, though I have not had to change the ServerName field and the ProxyPassReverse did not require the port number. So using your configuration, I would have tried:

ProxyPass / http://localhost:9069/
ProxyPassReverse / http://localhost/

Solution 3

If it helps someone: In my case only some requests were returning 400 code.

I fixed with:

ProxyPreserveHost On

Share:
14,839

Related videos on Youtube

Kishor N
Author by

Kishor N

Updated on September 18, 2022

Comments

  • Kishor N
    Kishor N almost 2 years

    I have an Odoo instance running on port 9069 in an Ubuntu server. Right now, apache is listening on port 8069 and is proxypass-ing this to 9069 (which works fine). The working URL is http://example.com:8069

    Now, I need to make this work with SSL on the front end URL. (https://example.com:8069). However this is giving me 400 Bad request error when accessed in a browser. The exact error is:

    Bad Request: Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.Apache/2.4.33 (Ubuntu) Server at example.com Port 8069

    Also I noticed the URL gets changed to http version too.

    The following is the virtualhost conf I've used for the domain.

    <IfModule mod_ssl.c>
    <VirtualHost *:8069>
    
      ServerName MySite
      ServerAlias example.com:8069
    
       SSLEngine on
       #SSLProxyEngine on
       SSLCertificateKeyFile /etc/apache2/sslfolder/mysite.key
       SSLCertificateFile    /etc/apache2/sslfolder/mysite.crt
       SSLCertificateChainFile /etc/apache2/sslfolder/mysite.txt
    
      ProxyPreserveHost On
      ProxyRequests Off
    
      ProxyPass /longpolling/ http://localhost:8072/
      ProxyPassReverse /longpolling/ http://localhost:8072/
    
      ProxyPass / http://localhost:9069/
      ProxyPassReverse / http://localhost:9069/
    
    </VirtualHost>
    </IfModule>
    

    Already checked the apache error logs, but there's no useful information there.

    Note: There is another virtualhost file for example.com, which is a pretty standard one with 80 and 443 ports configured. (It's just for the website, not odoo). I will post the virtualhost if you think it's relevant.