我的设置由两台服务器组成,一台用于托管网站,另一台用于处理繁重的工作(例如 Minecraft)。我使用 Spigot 来支持一些插件,其中一个插件是 dynmap(这是一个用于显示世界和在线玩家的交互式地图)。有关 dynmap 的更多信息请参见此处:https://github.com/webbukkit/dynmap
无论如何,我想在我的 Web 服务器上使用 ReverseProxy 并代理 dynmap 内容,这样我就可以关闭路由器上的某些端口。目前,我刚刚将端口 8123 转发到我的 Minecraft 服务器。
在 Web 服务器上,我目前运行的是 Apache 2.4,并且安装了 mod_proxy 和 mod_proxy_html。我还在 vhost 文件中为 HTTP 和 HTTPS 定义了以下内容:
ProxyRequests off
ProxyPass "/map" "http://192.168.2.31:8123/"
ProxyPassReverse "/map" "http://192.168.2.31:8123/"
这应该是不言自明的。但是当我访问页面 [WEBSITE]/map 时,我看到的是空白页。但我得到了这个:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Minecraft Dynamic Map</title>
<meta charset="utf-8" />
<meta name="keywords" content="minecraft, map, dynamic" />
<meta name="description" content="Minecraft Dynamic Map" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<!-- These 2 lines make us fullscreen on apple mobile products - remove if you don't like that -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="icon" href="images/dynmap.ico" type="image/ico" />
<script type="text/javascript" src="js/jquery-1.11.0.js?_=2.3-2074"></script>
<link rel="stylesheet" type="text/css" href="css/leaflet.css?_=2.3-2074" />
<script type="text/javascript" src="js/leaflet.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/custommarker.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/dynmaputils.js?_=2.3-2074"></script>
<!--<link rel="stylesheet" type="text/css" href="css/embedded.css" media="screen" />-->
<link rel="stylesheet" type="text/css" href="css/standalone.css?_=2.3-2074" media="screen" />
<link rel="stylesheet" type="text/css" href="css/dynmap_style.css?_=2.3-2074" media="screen" />
<!-- <link rel="stylesheet" type="text/css" href="css/override.css" media="screen" /> -->
<script type="text/javascript" src="version.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/jquery.json.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/jquery.mousewheel.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/minecraft.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/map.js?_=2.3-2074"></script>
<script type="text/javascript" src="js/hdmap.js?_=2.3-2074"></script>
<script type="text/javascript" src="standalone/config.js?_=2.3-2074"></script>
<script type="text/javascript">
$(document).ready(function() {
window.dynmap = new DynMap($.extend({
container: $('#mcmap')
}, config));
});
</script>
</head>
<body>
<noscript>
For full functionality of this site it is necessary to enable JavaScript.
Here are the <a href="http://www.enable-javascript.com/" target="_blank">
instructions how to enable JavaScript in your web browser</a>.
</noscript>
<div id="mcmap"></div>
</body>
</html>
我还在 dynmap 配置中将 Web 服务器定义为“受信任的代理”。所以我猜想 JavaScript 或图片以某种方式被阻止了?mod_security 未安装。
编辑
链接显示为 404,我应该在代理中添加子链接
编辑2
好的,我将这些行添加到 vhost 配置中,现在我收到的错误少了很多,这很重要。
ProxyRequests off
ProxyPass "/map" "http://192.168.2.31:8123/"
ProxyPass "/js" "http://192.168.2.31:8123/js/"
ProxyPass "/js/minecraft" "http://192.168.2.31:8123/js/minecraft/"
ProxyPass "/js/map" "http://192.168.2.31:8123/js/map/"
ProxyPass "/css" "http://192.168.2.31:8123/css/"
ProxyPass "/standalone" "http://192.168.2.31:8123/standalone/"
ProxyPassReverse "/map" "http://192.168.2.31:8123/"
ProxyPassReverse "/js" "http://192.168.2.31:8123/js/"
ProxyPassReverse "/js/minecraft""http://192.168.2.31:8123/js/minecraft/"
ProxyPassReverse "/js/map" "http://192.168.2.31:8123/js/map/"
ProxyPassReverse "/css" "http://192.168.2.31:8123/css/"
ProxyPassReverse "/standalone" "http://192.168.2.31:8123/standalone/"
我仍在试图弄清楚为什么服务器不向我发送位于 / 下的 .js 文件(见图)
编辑3
好吧,这很奇怪。但是如果我像这样删除最后一个反斜杠,目录 /standalone 中的 -js 文件就不会出现 404 错误。
ProxyPass "/standalone" "http://192.168.2.31:8123/standalone"
ProxyPassReverse "/standalone" "http://192.168.2.31:8123/standalone"
编辑4
好吧,至少取得了一些进展。像我之前编辑的那样编辑这些行确实给我带来了更多 404,但这次是来自图块和图像。所以这很好。
ProxyPass "/up/configuration" "http://192.168.2.31:8123/up/configuration"
ProxyPassReverse "/up/configuration" "http://192.168.2.31:8123/up/configuration"
答案1
您确实应该检查代理请求的 URI 映射规则。总体而言,更喜欢<Location>
处理代理内容。还请注意 Apache 中的 ProxyPassReverse 指令,以及其 Web 资源位置的 dynmap 配置。默认情况下,它使用相对路径,因此您应该做的就是
<Location "/map/"> ProxyPass http://192.168.2.31:8123/ </Location>
请注意,在这样的配置下,您的地图将依赖于服务器是否在线。
答案2
好吧,经过几个小时的反复尝试,以及许多不同的眼光审视,我最终想出了一个如下所示的配置:
ProxyRequests off
ProxyPass "/map" "http://192.168.2.31:8123/"
ProxyPass "/js" "http://192.168.2.31:8123/js/"
ProxyPass "/js/minecraft" "http://192.168.2.31:8123/js/minecraft/"
ProxyPass "/js/map" "http://192.168.2.31:8123/js/map/"
ProxyPass "/css" "http://192.168.2.31:8123/css/"
ProxyPass "/standalone" "http://192.168.2.31:8123/standalone"
ProxyPass "/up/configuration" "http://192.168.2.31:8123/up/configuration"
ProxyPass "/version.js" "http://192.168.2.31:8123/version.js"
ProxyPass "/images" "http://192.168.2.31:8123/images/"
ProxyPass "/tiles/world/t" "http://192.168.2.31:8123/tiles/world/t"
ProxyPass "/tiles/world/t_day" "http://192.168.2.31:8123/tiles/world/t_day"
ProxyPass "/tiles/world_nether/nt" "http://192.168.2.31:8123/tiles/world_nether/nt"
ProxyPass "/tiles/world_nether/flat" "http://192.168.2.31:8123/tiles/world_nether/flat"
ProxyPass "/tiles/world_the_end/st" "http://192.168.2.31:8123/tiles/world_the_end/st"
ProxyPass "/up/world/world" "http://192.168.2.31:8123/up/world/world"
ProxyPass "/up/world/world_nether" "http://192.168.2.31:8123/up/world/world_nether"
ProxyPass "/up/world/world_the_end" "http://192.168.2.31:8123/up/world/world_the_end"
ProxyPass "/mapimages" "http://192.168.2.31:8123/mapimages/"
ProxyPass "/tiles/_markers_" "http://192.168.2.31:8123/tiles/_markers_"
ProxyPass "/tiles/faces/16x16" "http://192.168.2.31:8123/tiles/faces/16x16"
ProxyPass "/tiles/faces/32x32" "http://192.168.2.31:8123/tiles/faces/32x32"
ProxyPassReverse "/map" "http://192.168.2.31:8123/"
ProxyPassReverse "/js" "http://192.168.2.31:8123/js/"
ProxyPassReverse "/js/minecraft""http://192.168.2.31:8123/js/minecraft/"
ProxyPassReverse "/js/map" "http://192.168.2.31:8123/js/map/"
ProxyPassReverse "/css" "http://192.168.2.31:8123/css/"
ProxyPassReverse "/standalone" "http://192.168.2.31:8123/standalone"
ProxyPassReverse "/up/configuration" "http://192.168.2.31:8123/up/configuration"
ProxyPassReverse "/version.js" "http://192.168.2.31:8123/version.js"
ProxyPassReverse "/images" "http://192.168.2.31:8123/images/"
ProxyPassReverse "/tiles/world/t" "http://192.168.2.31:8123/tiles/world/t"
ProxyPassReverse "/tiles/world/t_day" "http://192.168.2.31:8123/tiles/world/t_day"
ProxyPassReverse "/tiles/world_nether/nt" "http://192.168.2.31:8123/tiles/world_nether/nt"
ProxyPassReverse "/tiles/world_the_end/st" "http://192.168.2.31:8123/tiles/world_the_end/st"
ProxyPassReverse "/up/world/world" "http://192.168.2.31:8123/up/world/world"
ProxyPassReverse "/up/world/world_nether" "http://192.168.2.31:8123/up/world/world_nether"
ProxyPassReverse "/up/world/world_the_end" "http://192.168.2.31:8123/up/world/world_the_end"
ProxyPassReverse "/mapimages" "http://192.168.2.31:8123/mapimages/"
ProxyPassReverse "/tiles/_markers_" "http://192.168.2.31:8123/tiles/_markers_"
ProxyPassReverse "/tiles/faces/16x16" "http://192.168.2.31:8123/tiles/faces/16x16"
ProxyPassReverse "/tiles/faces/32x32" "http://192.168.2.31:8123/tiles/faces/32x32"
这对我而言是可行的,但我知道如果目录结构发生变化,我必须重新定义所有规则。使用此配置,一切都按预期运行。
如果你的世界名称不同,只需改变它的名称即可。
我还建议任何读者尝试“AnrDaemons”的建议