Apache 2.2,通过 ip.ip.ip.ip/folder 将 localhost:3000 上的服务器暴露给外部

Apache 2.2,通过 ip.ip.ip.ip/folder 将 localhost:3000 上的服务器暴露给外部

期望:localhost:3000ip.ip.ip.ip/folder

实际情况:ip.ip.ip.ip/folder打开了,但包含ip.ip.ip.ip/css/style.css相同的 JS 等链接。

目标:某些东西(apache conf?)以这样一种方式重写内容,使得所有链接都是ip.ip.ip.ip/folder/css/style.cssJS 等等。

看起来它应该可以工作,因为 localhost:3000 没有使用相关 URL,但不知何故却没有。

我不明白什么?我该如何解决?

地点:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        RewriteEngine On
        RewriteLog "/var/log/apache2/rewrite.log"
        RewriteLogLevel 3
        RewriteRule ^/folder/(.*)$ http://127.0.0.1:3000/$1 [L,P]
        ProxyPassReverse /folder/ http://127.0.0.1:3000/

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

加载 apache 模块(可能太多了,我尝试了很多东西):

core_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
negotiation_module (shared)
php5_module (shared)
proxy_module (shared)
proxy_html_module (shared)
proxy_http_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
substitute_module (shared)

编辑:

重写日志输出:

(2) init rewrite engine with requested uri /folder/
(3) applying pattern '^/folder/(.*)$' to uri '/folder/'
(2) rewrite '/folder/' -> 'http://127.0.0.1:3000/'
(2) forcing proxy-throughput with http://127.0.0.1:3000/
(1) go-ahead with proxy request proxy:http://127.0.0.1:3000/ [OK]
(2) init rewrite engine with requested uri /css/style.css
(3) applying pattern '^/folder/(.*)$' to uri '/css/style.css'
(1) pass through /css/style.css

编辑:

找到了一些很好的资源和解决方案:

尽管如此,仍然无法在 CSS 中重写 URL。

答案1

确实没有必要使用 mod_rewrite 来进行代理,这里就完全足够了。ProxyPass /folder/ http://localhost:3000/

对于 css/js/image 问题,您有几个选择。到目前为止,最好的方法是更改​​底层应用程序,以便将 deplyos 更改为 '/folder/' 而不是 '/',然后您可以使用

ProxyPass /文件夹/ http://localhost:3000/文件夹/

并且它应该全部正常工作,应用程序、css 等都由单个指令覆盖。如果您无法做到这一点,那么您可以使用类似的东西,但当然您需要对使用的每个文件夹执行此操作。ProxyPass /css/ http://localhost:3000/css/

最后,您可以升级到 apache v2.4 并使用 mod_proxy_html 直接“纠正” HTML/css/js 中的 URI 路径。

答案2

您似乎对 ProxyPassReverse 和重写规则有一些误解。这应该对您有用:

RewriteEngine on
RewriteRule ^/folder/(.*)$ http://localhost:3000/$1 [L,P]
ProxyPassReverse /folder/ http://localhost:3000/

相关内容