How to correctly configure a reverse proxy with Apache, to be used for cross-domain AJAX?

前端 未结 4 654
鱼传尺愫
鱼传尺愫 2021-02-02 18:05

Needing to develop a web application that at the same time is highly dependent on an API but at the same time cannot reside on the same domain as the API itself, it\'s been quit

4条回答
  •  醉话见心
    2021-02-02 18:57

    on 127.0.0.1, your html code should be:

    $.ajax({
        url: "http://127.0.0.1/a/w/currencies",
        type: "GET",
        dataType: "json",
        data: {
        },
        success: function(data){
            console.log(data);
        }
    }); 
    

    on 127.0.0.1, your apache conf should be:

    ...
    
    
                ...
                ProxyPass / https://app.somesite.com:5002/
                ProxyPassReverse / https://app.somesitecom:5002/
                ...
    
    

    on this case, your browser will not cross-domain, because your url and ajax use the same domain.But exactly, ajax request https://app.somesite.com:5002/ , I don't know if it is a reverse-proxy ,but it seems work for me. Have a try :)

提交回复
热议问题