您的位置:首页 > 运维架构 > Apache

Installing Mod-Proxy-Html and Proxying Virtuoso Via Apache2

2011-02-12 20:07 1031 查看

 

Contents

[hide] 1 Introduction 2 Installing Mod-Proxy-Html on Ubuntu 3 Installing Mod-Proxy-Html on any Linux Distribution 4 Configuring Apache2 For Proxying Virtuoso Queries 5 References

Introduction

Sometimes it may not be possible to access the Virtuoso back-end (such as its Conductor or SPARQL user interface) via its default port 8890. There exists setups where you only have the HTTP and SSH ports open, and that you can't do otherwise. However, you have to have Apache2 running on port 80, and you have to have Virtuoso running on another port (let's say: 8890). In that case, you have to proxy all Virtuoso queries via Apache2 using mod-proxy and mod-proxy-html. For this tutorial, we consider that all basic Linux distributions have installation packages for Apache2 that includes mod-proxy by default. If it is not the case, you will have to install mod-proxy first. This tutorial is about installing mod-proxy-html only, and to configure mod-proxy and mod-proxy-html for proxying Virtuoso queries via Apache2.

Installing Mod-Proxy-Html on Ubuntu

Installing mod-proxy-html on Ubuntu is as simple as running this apt-get installation command: apt-get install libapache2-mod-proxy-html ------------------- 配置: 1.加载模块:
sudo a2enmod proxy
sudo a2enmod proxy_html

2. 开启代理功能:
sudo vim /etc/apache2/mods-enabled/proxy.conf
- change to:

AddDefaultCharset off
#Order deny,allow
#Deny from all
#Allow from .example.com
Order allow,deny
Allow from all

- warning: you might want to restrict that a little to your networks
3.例子:
sudo apt-get install libapache2-mod-proxy-html
sudo a2enmod proxy sudo a2enmod proxy_html
sudo vim /etc/apache2/mods-enabled/proxy.conf - change to: AddDefaultCharset off #Order deny,allow #Deny from all #Allow from .example.com Order allow,deny Allow from all - warning: you might want to restrict that a little to your networks
sudo vim /etc/apache2/sites-enabled/000-default
- Under put some forwarding parameters e.g.:
ProxyPass /instance1 http://172.19.1.2
sudo /etc/init.d/apache2 reload

Navigate to http://cc/instance1 and you should be redirected to web server running on instance at private address 172.19.1.2 (change the rule to match your instance address and make sure it's running a webserver!)

-----------------------------------------------------------------------------

 

Installing Mod-Proxy-Html on any Linux Distribution

In this case, we have a Linux distribution which has a pre-packaged version of Apache2 that comes with mod-proxy, but that doesn't come with mod-proxy-html. It is the case with CentOS 5 for example.
In that case, you have no other choices than downloading the source, and to compile it.
First, go to the temp folder of your distribution:
cd /tmp
Then download the mod-proxy-html source codes:
wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.zip Then unzip the source:
unzip mod_proxy_html.zip
cd mod_proxy_html
Then you have to make sure you have the libxml2 development toolkit installed on your system. The library is installed on any Linux distribution, but not the developer toolkit. Lets consider that you have access to the libxml2-devel RPM package and YUM:
yum install libxml2-devel
Then the next step is to make sure that you have the apache2 developer toolkit installed on your server as well. We need the apxs software to compile the module. Lets install it:
yum install httpd-devel
Then the next step is to compile the mod-proxy-html and the mod-xml2enc modules:
apxs -c -I/usr/include/libxml2 -I. -i mod_proxy_html.c
apxs -c -I/usr/include/libxml2 -I. -i mod_xml2enc.c
The apxs application will compile the module and will install it into the modules folder of your Apache2 server.
-----------------------
配置:
Add necessary directives in httpd.conf:

 

LoadFile /usr/lib/libxml2.so

LoadModule proxy_html_module modules/mod_proxy_html.so

LoadModule mod_xml2enc modules/mod_xml2enc.so

 

然后: service httpd restart 即可。

--------------------------------------------
 
 
-----------------------------------------------------

Configuring Apache2 For Proxying Virtuoso Queries

Now is the time to configure Apache2 to proxy Virtuoso queries. A simple configuration file for Apache2 looks like:
#  Disable global proxy
ProxyRequests       Off

#  Pass original host to Virtuoso
ProxyPreserveHost   On

#  Timeout waiting for Virtuoso
ProxyTimeout        300

#  Set permission

Order deny,allow
Allow from all

#ProxyHTMLLogVerbose On
#LogLevel Info
#LogLevel Debug

# Configuring the links that will be re-written
ProxyHTMLLinks  a               href
ProxyHTMLLinks  area            href
ProxyHTMLLinks  link            href
ProxyHTMLLinks  img             src longdesc usemap
ProxyHTMLLinks  object          classid codebase data usemap
ProxyHTMLLinks  q               cite
ProxyHTMLLinks  blockquote      cite
ProxyHTMLLinks  ins             cite
ProxyHTMLLinks  del             cite
ProxyHTMLLinks  form            action
ProxyHTMLLinks  input           src usemap
ProxyHTMLLinks  head            profile
ProxyHTMLLinks  base            href
ProxyHTMLLinks  script          src for

ProxyHTMLEvents onclick ondblclick onmousedown onmouseup /
onmouseover onmousemove onmouseout onkeypress /
onkeydown onkeyup onfocus onblur onload /
onunload onsubmit onreset onselect onchange

# Defining the URLs to proxy

ProxyPass               http://localhost:8890/ ProxyPassReverse        /
ProxyHTMLEnable         On
ProxyHTMLURLMap         / /virtuoso/
ProxyHTMLURLMap         http://localhost:8890/ /virtuoso/

What it does is to forward any queries has a URL of the form: "http://mydomain.com/virtuoso/", into a query to the virtuoso server located at: "http://localhost:8890/". Then it will return the results to the user.
What is important here is the mod-proxy-html module. What it does is to make sure that if you click on a link, within the web page, that this links refers to the same server as well. So, what this module does is really to rewrite the links within the HTML web page that is proxied such that they are consistent according to the ProxyHTMLURLMap rules.

References

http://apache.webthing.com/mod_proxy_html/
http://www.apachetutor.org/admin/reverseproxies
http://docs.openlinksw.com/virtuoso/webserver.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: