Apache 2.2,通过ip.ip.ip.ip /文件夹将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.css和JS等等。

它似乎应该作为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 

编辑:

find了一些很好的资源和解决scheme:

  • https://stackoverflow.com/questions/14431090/proxyhtml-to-rewrite-url

  • http://www.askapache.com/hosting/reverse-proxy-apache.html

尽pipe如此,仍然挣扎着不重写CSS内部的URL。

这里真的没有必要使用mod_rewrite来进行代理, ProxyPass /folder/ http://localhost:3000/将是完全足够的。

对于CSS / JS /图像的问题,你有几个select。 到目前为止,最好的方法是改变底层的应用程序,使得deplyos为'/ folder /'而不是'/',那么你可以使用

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

它应该只是工作,应用程序,CSS等所有覆盖一个单一的指令。 如果你不能这样做,那么你可以使用像ProxyPass /css/ http://localhost:3000/css/ ,但是当然你需要为每个使用的文件夹做这件事。

最后,您可以升级到Apache v2.4,并使用mod_proxy_html直接在HTML / css / js中“纠正”URIpath。

您似乎对ProxyPassReverse和Rewrite Rules有一些误解。 这应该为你工作:

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