apache mod_proxy, configuring ProxyPass & ProxyPassReverse for cross-domain ajax calls

后端 未结 3 1309
暗喜
暗喜 2020-12-14 22:41

I\'m creating an html5 - JavaScript app (for mobile devices, using PhoneGap). I have to interact with a REST service.

The service is now running on \"http://lo

相关标签:
3条回答
  • 2020-12-14 22:55

    You could simply add the given lines in the httpd.conf after enabling the proxy modules.

    ProxyPreserveHost On
    ProxyPass /EMBackend http://localhost:8080/backend/mvc
    ProxyPassReverse /EMBackend http://localhost:8080/backend/mvc
    

    Just restart the server and you are done.

    0 讨论(0)
  • 2020-12-14 23:05

    I found a working solution:

    Enable:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    

    Put this in the main section of your configuration (or desired virtual host, if using Apache virtual hosts):

    ProxyRequests Off
    ProxyPreserveHost On
    
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    
    ProxyPass /EMBackend http://localhost:8080/backend/mvc
    ProxyPassReverse /EMBackend http://localhost:8080/backend/mvc
    <Location /EMBackend>
        Order allow,deny
        Allow from all
    </Location>
    

    So I guess I can't put it in .htaccess or I had to set ProxyPreserveHost On. I put Include conf/extra/ in the httpd.conf file and created the httpd-proxy.conf file and put the script above in it. Restarted apache and it's working!

    0 讨论(0)
  • 2020-12-14 23:15

    In very modern apache, turn on proxy by:

    a2enmod proxy;
    a2enmod proxy_http
    
    0 讨论(0)
提交回复
热议问题