简体   繁体   English

为跨域Ajax调用配置apache mod_proxy

[英]Configuring apache mod_proxy for cross-domain ajax calls

I started working on a small JavaScript app today that utilizes the Clipped API ( http://clipped.me/api.html ), but learned that there are cross-domain AJAX call issues, and the developer of the API didn't add support for JSONP. 我今天开始开发一个使用Clipped API( http://clipped.me/api.html )的小型JavaScript应用程序,但了解到存在跨域AJAX调用问题,并且该API的开发人员没有添加支持JSONP。 Here's the app itself: 这是应用程序本身:

var clippedAPI = "http://clipped.me/algorithm/clippedapi.php";

    $.ajax({
        url: clippedAPI,
        type: "GET",
        dataType: "JSONP",
        data: {
        url: "http://pandodaily.com/2013/03/26/y-combinator-demo-day-2013-still-looking-for- the-next-airbnb-or-dropbox/"}
    }).done(function(json) {
        console.log("JSON Data: " + json.title );
    }).fail(function(jqxhr, textStatus, error){
        var err = textStatus + ', ' + error;
        console.log("Request Failed: " + err);
});

I've set up an Apache server on my Ubuntu machine, and have been suggested to use mod_proxy to set up a reverse proxy. 我已经在Ubuntu计算机上设置了Apache服务器,建议使用mod_proxy设置反向代理。 The problem is that I just don't know how to do this -- this is my first time using Apache. 问题是我只是不知道该怎么做-这是我第一次使用Apache。 I know all the basics like accessing my main Apache config files in Terminal. 我知道所有基本知识,例如在Terminal中访问我的主要Apache配置文件。 Can anyone give a noob a run-down on how to do this? 谁能给菜鸟一个简单的方法呢?

Apache mod_proxy in Ubuntu Ubuntu中的Apache mod_proxy

Setting up a reverse proxy using Apache in Ubuntu: 在Ubuntu中使用Apache设置反向代理:

1. Install reverse_proxy module 1.安装reverse_proxy模块

sudo apt-get install libapache2-mod-proxy-html

2. Install libxml if it is not already installed. 2.如果尚未安装libxml,请安装它。

apt-get install libxml2-dev

3. Load the modules in apache2.conf file 3.将模块加载到apache2.conf文件中

LoadModule  proxy_module         /usr/lib/apache2/modules/mod_proxy.so
LoadModule  proxy_http_module    /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule  headers_module       /usr/lib/apache2/modules/mod_headers.so
LoadModule  deflate_module       /usr/lib/apache2/modules/mod_deflate.so
LoadFile    /usr/lib/libxml2.so

4.Say you want to forward all requests starting to internal.server then add the following to your apache2.conf file 4,假设您要将所有请求转发到internal.server,然后将以下内容添加到apache2.conf文件中

# Disable proxy requests, using ProxyPass in vhost
ProxyRequests Off

# Block all requests
<Proxy *>
  Order deny,allow
  Deny from all
</Proxy>


<Proxy balancer://cluster>
        BalancerMember http://internal.server:802
        BalancerMember http://internal.server:801
        #below is to transfer sessions
        #ProxySet lbmethod=bytraffic

</Proxy>


<Location /balancer-manager>
    SetHandler balancer-manager
    Order Deny,Allow
#   Deny from all
    Allow from all
</Location>

5.Hopes you are good to go.! 5,希望你一切顺利!

update: 更新:

sudo  aptitude download libxml2
sudo  ar -xf libxml2_2.7.8.dfsg-5.1ubuntu4_amd64.deb

the following files will be extract from ubuntu package. 以下文件将从ubuntu软件包中提取。
control.tar.gz data.tar.gz debian-binary libxml2_2.7.8.dfsg-5.1ubuntu4_amd64.deb control.tar.gz data.tar.gz debian-binary libxml2_2.7.8.dfsg-5.1ubuntu4_amd64.deb

# rm libxml2_2.7.8.dfsg-5.1ubuntu4_amd64.deb control.tar.gz
# tar xf data.tar.gz
# cd usr/lib/x86_64-linux-gnu/
# ls

The following files will be there 以下文件将在那里
libxml2.so.2 libxml2.so.2.7.8 libxml2.so.2 libxml2.so.2.7.8

# mv * /usr/lib/x86_64-linux-gnu/
# cp /usr/lib/x86_64-linux-gnu/libxml2.so.2* /usr/lib/
# /etc/init.d/apache2 start
  • Starting web server apache2 [ OK ] 启动Web服务器apache2 [确定]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM