反向代理
uniGUI的反向代理可以解决从内网部署到外网上,并且只占用外网的一个端口,反向代理是独立运行的,可以使用HyperServer进行负载均衡,使用http路径访问。
部署步骤:
1.unigui程序设置
首先在uniGUI程序中设置 Port 和 UrlPath ,这是为稍后在Apache中加载做准备,为了更好的配置,可以将这两个参数写成配置文件,进行读入更好。
代码参考:
uses
vcl.Forms,iniFiles
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);
var
iniFile: TiniFile;
fnIni: string;
begin
fnIni := ExtractFilePath(ParamStr(0) )+ 'Setup.ini';//放到和程序相同路径下
iniFile := TiniFile.Create(fnIni);
try
UniServerModule.Port := iniFile.ReadInteger('app', 'port', 8077);
UniServerModule.UrlPath := iniFile.ReadString('app', 'urlpath', ''); // 字符串
finally
iniFile.Free;
end;
end;
2.Apache文件配置
httpd.conf
在Apache的安装目录的bin下,找到http.conf文件,打开文件,找到:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Include conf/extra/httpd-vhosts.conf
将以上三个文件启用,也就是前面的 “#” 去掉
httpd-vhosts.conf
在Apache的安装目录的conf\extra目录下加入以下代码:
<Location /td>
ProxyPass http://127.0.0.1:8079
ProxyPassReverse http://127.0.0.1:8079
</Location>
注:此时的td是和刚刚在uniGUI中设置的URLPath是一致的
此时设置好之后,可能还会有一个问题,要先将Apache的默认端口路径给注释掉,如下:
3.重启
以上设置结束之后,重启一下 Apache即可
4.访问方式
输入地址,http://go.giga-force.com:8004/td 即可访问
注: 域名+端口+程序名