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

后端 未结 3 1325
暗喜
暗喜 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 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
    
    
        Order deny,allow
        Allow from all
    
    
    ProxyPass /EMBackend http://localhost:8080/backend/mvc
    ProxyPassReverse /EMBackend http://localhost:8080/backend/mvc
    
        Order allow,deny
        Allow from all
    
    

    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!

提交回复
热议问题