0

I'm trying to setup a simple web app and I'm having some difficulties.

Here's how I have it setup :

/srv/www/application <-- python code /srv/www/public_html <-- document root 

I want Apache to serve everything in public_html if he can find it, else send the request to my application.

a snippet of my virtual host file :

 DocumentRoot /srv/www/public_html <Directory /srv/www/public_html> Options -Indexes RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ../application/code.py/$1 [L] </Directory> 

I'm really not sure about the ../application, (because I think it rewrites to a url, not a directory), and I suspect this is why it's not working, but I can't find a way to make it work.

Update

I've applied Cakemox suggestion, but there was still some problems. Here's what I did :

WSGIScriptAlias / /srv/www/application/code.py 

This route everything to my application. Strangely, it worked for a moment, i.e file found inside public_html was served and the rest was routed to my application, but I guess the browser's cache was playing tricks on me.

I also tried :

WSGIScriptAlias /application /srv/www/application/code.py <Directory /srv/www/public_html> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ application/$1 [L] </Directory> 

This worked most of the time, except that the default url (mydomain.com) was listing my public_html directory instead of running the app. I guess it's because the requested filename is /srv/www/public_html, which is a directory so the condition is false. It's weird because I've numerous app running perfectly fine with those conditions...

Update 2 After almost 2 days of head-smashing-on-keyboard (I can touch my brain now), I think I finally got it. The "numerous app" I was referring to in the last paragraph were mostly PHP apps where the application index.php is in the public_html folder. So browsing mydomain.com, Apache first search for the default index (DirectoryIndex) before applying any rewriting rules. Since I do not have any index.php, index.htm or index.html in my public_html folder, it just listed the directory. So to fix this, I can either add DirectoryIndex /application or RewriteRule ^$ /application before the conditions. Here's the final snippet :

<Directory /srv/www/public_html> DirectoryIndex /application RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ application/$1 [L] </Directory> 

Thanks.

2 Answers 2

1

Alias comes to mind:

Alias /application "/srv/www/application" 
4
  • Yes, but since my public_html folder will be (somewhat) public, someone could create an "application" directory and break the whole thing, because Apache will serve the directory instead of the app. Commented Oct 11, 2010 at 9:30
  • The alias directive has priority over whatever is in the document root. Even if someone adds an application directory, the alias takes precedence. Commented Oct 11, 2010 at 9:40
  • You're right. I guess I was just trying too much with mod_rewrite. Thanks! Commented Oct 11, 2010 at 10:34
  • I guess it didn't work after all. See update. Commented Oct 11, 2010 at 19:28
0

I do this all the time via symbolic links:

ln -s /path/to/target localname 

This only works when the target path is on the same partition.

You can also use bind mounts:

mount --bind /path/to/orig/dir newdir/path 

And you can keep bind mounts active after restart in /etc/fstab:

/my/real/dir /to/mount/dir auto rw,bind 0 0 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.