apache2 Allow access to subdirectory

10,280

Solution 1

The key to my problem was identifying how to override Passenger, which is what is running the Django app. Access your httpd.conf file. Within the main Virtualhost section (the one that defines your domain and how the public folder is handled) place this code to override Passenger and Django's grip on the /* directory.

Alias /blog /home/user/domain/public/blog

<Directory /home/user/domain/public/blog>
PassengerEnabled off
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>

Adding PassengerEnabled off takes care of Passenger and allows the Directory to be served outside of the Django app. I don't think AllowOverride or Allow from all does much of anything but I left it in just to be safe. Works perfectly now.

Solution 2

Try adding an Apache Alias directive:

Alias /blog/  /home/user/domain/public/blog/

That 'Alias' will along with your 'Directory' directive should do the trick.

Note: I have these listed before my wsgi configuration that loads django into apache. ( I dont know if that matters tho, but it might.)

Edit: In my main httpd. conf file I

LoadModule wsgi_module modules/mod_wsgi.so

I assume there are 'DocumentRoot' and 'Directory' directives in there.

Next: in my virtual host

<VirtualHost *:80>
Alias /blog/  /home/user/domain/public/blog/

<FilesMatch \.(?i:gif|jpe?g|png|ico)$>
  Order allow,deny
  allow from all
</FilesMatch>

<FilesMatch \.(?i:css|jst|js|txt|htm|html)$>
  Options Indexes FollowSymLinks MultiViews
  Order allow,deny
  allow from all
</FilesMatch>

<Directory /home/user/domain/public/blog/>
   Order allow,deny
   allow from all
</Directory>

Maybe my FilesMatch directives were actually doing the magic ( I might have missed that before)

Debugging If you cant get this going, you might want to enable more verbose httpd logging output in apache to see if you can get it to tell you what it is unhappy about. you do this by changing the 'LogLevel' directive from 'warn' to debug

LogLevel debug

now

tail -f /path/to/you/apache/error_logs
Share:
10,280
Carl W.
Author by

Carl W.

Creative Director and professional Dad. I do it for a living.

Updated on June 07, 2022

Comments

  • Carl W.
    Carl W. almost 2 years

    I am currently running a Django site on Dreamhost using Passenger. I would like to run a Wordpress blog in the 'public' directory that currently holds my static files (which is where I assume it should live). Since Django currently owns all of /*, I was told I would need to add a Location entry to the httpd.conf of my apache2 server. I tried both Location and Directory and could not get them to work. The code snippet below is basically what I typed in a bunch of different ways.

    <Directory /home/user/domain/public/blog/>
    Order allow,deny
    allow from all
    </Directory>
    

    I also tried adding AllowOverride All to try and catch the htaccess file in the blog folder but no dice. I am extremely new to messing with apache (first time), can anyone point me in the right direction to get /blog/ to show the wordpress site and not a 404 page.