Setting up basic proxy from https to http via Apache

5,501

This should be all you need:

RewriteEngine On
RewriteRule ^/api/(.*)$ https://example.com/api/$1 [P,QSA,L]

Apache will basically proxy your requests by creating new http requests via the mod_rewrite module, which is enabled by default

Share:
5,501

Related videos on Youtube

Dan
Author by

Dan

Updated on September 18, 2022

Comments

  • Dan
    Dan over 1 year

    I need to proxy some remote api https://example.com/api/

    to be accessible locally as http://localhost/api/

    I tried putting this line in httpd.conf:

     ProxyPass     /api/     https://example.com/api/
    

    I have checked these modules are enabled:

     ssl_module, proxy_module, proxy_http_module  
    

    When I'm trying to reach http://localhost/api/, I'm getting 500 Internal Server Error, And what I see in error_log is:

    [Wed Jan 14 16:42:04.788401 2015] [proxy:warn] [pid 21916] [client ::1:59260] AH01144: No protocol handler was valid for the URL /api/v1/ads. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.  
    

    My question is relative to this one: https://stackoverflow.com/questions/1997001/setting-up-a-basic-web-proxy-in-apache. Actually, when I try to proxy http resources, everything works for me, so the problem is somewhere around SSL.

    The reason I want this to work is the Access-Control-Allow-Origin problem I'm experiencing when working with remote api locally.


    UPDATE

    Here's the entire conf file. https://www.dropbox.com/s/mkrxna4h2o9yu8k/httpd.conf?dl=0

  • Dan
    Dan over 9 years
    Thank you for trying to help! I've uploaded the entire conf file and attached it to the question. Btw, after applying your answer, I get the following in error_log: [ssl:error] [pid 22221] [remote 54.149.6.238:443] AH01961: SSL Proxy requested for macs-MacBook-Pro.local:80 but not enabled [Hint: SSLProxyEngine] [Wed Jan 14 17:49:37.661756 2015] [proxy:error] [pid 22221] AH00961: HTTPS: failed to enable ssl support for 54.149.6.238:443 (api-staging.ad-rapid.com)
  • Dan
    Dan over 9 years
    Plus check if rewrite_module module is on, I suggest
  • Dan
    Dan over 9 years
    And that worked!