0

In order to make my life easier with new vhosts popping up I set up my httpd.conf to use this:

<IfModule mod_vhost_alias.c>
  <VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
    RewriteRule ^(.*)$ - [env=askapache:%2]

    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]

    ServerAlias *
    UseCanonicalName Off
    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon
    VirtualDocumentRoot /web-data/vhosts/%0/httpdocs
    VirtualScriptAlias  /web-data/vhosts/%0/httpdocs
  </VirtualHost>
</IfModule>

The problem is one of the hosts needs to make use of a ProxyPass statement. I was just going to put that in a separate conf file in a conf folder in that sites root (not Doc Root outside the httpdocs folder). However I can't figure out how to do that and include it with the dynamic virtual hosting. What can I do to set up a ProxyPass just for this one host without messing up the dynamic virtual hosting setup I have?

Edit:

I've tried the following in my .htaccess file to no avail. I get a 404

RewriteEngine on
RewriteRule ^blog/$ http://blog.mydomain.com [P,L]
LoneWolfPR
  • 275
  • 1
  • 3
  • 17

1 Answers1

0

You can probably define your proxies in a separate conf file in Apache conf dir and then use the rewrite rules with the P flag (which uses mod_proxy under the hood) in an htaccess file.

alxgomz
  • 1,630
  • 1
  • 11
  • 14
  • How would I go about doing that? – LoneWolfPR Apr 21 '14 at 15:41
  • Check the documentation here: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p – alxgomz Apr 21 '14 at 15:48
  • This seems overly complicated to include mod_rewrite as well. Isn't there a way to tell the system to just include an external conf file in each vhosts conf folder? Then I could just put a ProxyPass in there. – LoneWolfPR Apr 21 '14 at 19:55
  • This is what "Include" does but you most definitely dont want to include any file in any of your vhosts webroot, where people can upload almost anyhthing they want. That's why htaccess is for, and thats why not all directive can be used in htaccess. Proxypass cant. Rewriterules can... i dont really understand what you find so complicate here though. – alxgomz Apr 21 '14 at 22:38
  • Check the edit I made. I've tried adding that, but it still just gives me a 404 when I go to http://www.mydomain.com/blog instead of doing the proxy. I double checked and mod_proxy is enabled in my httpd.conf file. Is there something I missed? – LoneWolfPR Apr 22 '14 at 18:13
  • Did you add this htaccess file in the /blog directory? Remember that using rewrite rules in a per directory context is different from using it in avhost or server context read the chapter "Per-directory Rewrites" in the following link: http://httpd.apache.org/docs/2.2/en/mod/mod_rewrite.html#rewriterule . you can also check where your rule matches using the RewriteLog and RewiteLogLevel directives. I guess going to http://blog.mydomain.com is no problem? – alxgomz Apr 23 '14 at 06:42
  • I actually didn't have a blog directory. I created one and put this in a .htaccess there. I get a 403 Forbidden error when I try to go to it. I do have RewriteEngine On, and I double checked that FollowSymLinks is enabled. – LoneWolfPR Apr 23 '14 at 13:21
  • Maybe i was not clear but really, what you should focus on is debugging your rewrite rules using the log directives I pointed out. I guess the forbidden access comes from the fact directory listing is not allowed on your setup. – alxgomz Apr 24 '14 at 05:44
  • Thanks. I missed the stuff about the rewrite logging. Tried it, and (according to the logs) it's definitely not even attempting the pass through. – LoneWolfPR Apr 24 '14 at 14:18
  • Can you pirate logs somewhere? – alxgomz Apr 24 '14 at 17:35