大网数据广告活动
服务器运维问答

Apache 2.2, exposing server on localhost:3000 to outside through ip.ip.ip.ip/folder

· 52CE 我爱测

Expectation: localhost:3000 works under ip.ip.ip.ip/folder Reality: ip.ip.ip.ip/folder opens, but contains ip.ip.ip.ip/css/style.css and same for JS and so on links. Goal: something (apache conf?) rewrites the stuff in such a way…

问题原文

原帖链接 · LauriK · CC BY-SA 3.0

Expectation: localhost:3000 works under ip.ip.ip.ip/folder

Reality: ip.ip.ip.ip/folder opens, but contains ip.ip.ip.ip/css/style.css and same for JS and so on links.

Goal: something (apache conf?) rewrites the stuff in such a way that all the links are ip.ip.ip.ip/folder/css/style.css and JS and so on.

It seems like it should work as the localhost:3000 is not using relatives URLs, but somehow it doesn't.

What am I not understanding and how can I fix it?

Site:

<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>

Loaded apache modules (probably a few too many, I've tried a whole bunch of things):

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)

edit:

Rewritelog output:

(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

Edit:

Found a couple of good resources and solutions:

Still struggling with it not rewriting the URLs inside CSS though.

已采纳解答

原帖链接 · Unbeliever · CC BY-SA 3.0

There really is no need to use mod_rewrite to do the proxying here ProxyPass /folder/ http://localhost:3000/ will be entirely sufficient.

For the css/js/image problem you have a few options. By far the best is to change the underlying application so that is deplyos as '/folder/' rather than '/', then you can just use

ProxyPass /folder/ http://localhost:3000/folder/

And it should all just work, application, css etc all coverd by a single directive. If you cannot do this, then you can use things like ProxyPass /css/ http://localhost:3000/css/, but of course you need to do it for each folder used.

Finally you can upgrade to apache v2.4 and use mod_proxy_html to 'correct' the URI paths in the HTML/css/js directly.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。