3

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.

1

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.

  • Ah, the second option is clever - I never understood it before, but it would indeed work. The whole reason for doing is that I will have several applications running on that server that I want to expose under various paths. – LauriK Sep 23 '16 at 15:32
2

You seem to have some misconceptions about ProxyPassReverse and Rewrite Rules. This should work for you:

RewriteEngine on
RewriteRule ^/folder/(.*)$ http://localhost:3000/$1 [L,P]
ProxyPassReverse /folder/ http://localhost:3000/
  • It should, but does not. I've amended the configuration and appended the rewritelog output to the post. – LauriK Sep 23 '16 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.