上述的对Apache虚拟主机的配置过程,主要在于三个部分:Apache,launcher,pvw,主要的配置在前面,通过Apache来分发用户,通过launcher来为用户启动pvw的进程。
我的理解:给Apache配置虚拟主机是为了把Apache当做一个虚拟的主机供用户访问,用户直接访问的是Apache,但实际上是通过Apache来访问pvw,该虚拟主机访问链接是:http://localhost:port;launcher.conf中配置了真正要访问的主机的sessionURL,虚拟主机中设定一种重写规则,通过这个规则去匹配launcher.conf,当用户访问的时候,虚拟主机为用户设定一个id用于区分不用用户,并且记录在proxy.txt中,然后去launcher.conf中匹配,从设定好的端口范围中选取一个,以这个ws://${host}/proxy?sessionId=${id}组合成的sessionURL去访问pvw,从而为该用户启动一个后台的程序;Apache分发的不同用户通过proxy.txt与launcher进行匹配,从而保证了不同用户请求与响应的分离。
官网上有两种方式来配置,一种是Apache与launcher在一台主机上,另外一种是这两部分放在不同的主机上,通过配置文件的比较,发现配置文件区别不是很大,只是在于launcher.conf中对host的设置,另外有一个jetty launcher,没用到,所以没仔细看。配置文件粘贴如下,官网网址点击打开链接。
在一台主机上Apache虚拟主机:
*:80>
ServerName host1.example.com
...
# Handle launcher forwarding
ProxyPass /paraview http://localhost:8080/paraview
# Handle WebSocket forwarding
RewriteEngine On
RewriteMap session-to-port txt: /proxy.txt
RewriteCond %{QUERY_STRING} ^sessionId=(.*)$ [NC]
RewriteRule ^/proxy.*$ ws://${session-to-port:%1}/ws [P]
在一台主机上launcher.conf:
{
"resources": [ {"host": "localhost", "port_range": [9001, 9003] } ],
...
"configuration": {
"host": "localhost",
"port": 8080,
"sessionURL": "ws://host1.example.com/proxy?sessionId=${id}",
"proxy_file": "/proxy.txt"
},
...
"apps": {
...,
"visualizer": {
"cmd": [
"${python_exec}", "${python_path}/paraview/web/pv_web_visualizer.py",
"--port", "${port}", "--data-dir", "${dataDir}", "-f", "--authKey", "${secret}"
],
"ready_line" : "Starting factory"
},
...
}
}
在两台主机上Apache虚拟主机:
*:80>
ServerName host1.example.com
...
# Handle launcher forwarding
ProxyPass /paraview http://host2.example.com:8080/paraview
# Handle WebSocket forwarding
RewriteEngine On
RewriteMap session-to-port txt: /proxy.txt
RewriteCond %{QUERY_STRING} ^sessionId=(.*)$ [NC]
RewriteRule ^/proxy.*$ ws://${session-to-port:%1}/ws [P]
在两台主机上launcher.conf:
{
"resources": [ {"host": "host2.example.com", "port_range": [9001, 9003] } ],
...
"configuration": {
"host": "localhost",
"port": 8080,
"sessionURL": "ws://${host}/proxy?sessionId=${id}",
"proxy_file": "/proxy.txt"
},
...
"apps": {
...,
"visualizer": {
"cmd": [
"${python_exec}", "${python_path}/paraview/web/pv_web_visualizer.py",
"--port", "${port}", "--data-dir", "${dataDir}", "-f", "--authKey", "${secret}"
],
"ready_line" : "Starting factory"
},
...
}
}