apache2 Allow access to subdirectory - django

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.

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

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.

Related

Rewrite Rule to redirect everything in a directory to root of site

I just set up my first VPS. I have a primary domain - "mysite.com". I am hosting other websites within the directory of the primary domain. So that they are organized, I have placed them in a folder called "sites".
The problem is that i am able to reach the secondary sites by going to "mysite.com/sites/othersite/index.php as well as by the secondary domain's url.
I know I need to use .htaccess to fix this. so far I have tried the following after some research:
RewriteRule ^/sites/(.*)$ http://www.othersite.com/$1 [R=301,L]
This DOES rewrite mysite.com/sites/ back to the root url, but mysite.com/sites/othersite/index.php still produces a copy of othersite.com
I am looking for a rewrite rule or set of rules that will redirect absolutely any request for anything (files, subfolders, etc) in the /sites/ directory to the root directory (mysite.com)
That's not the way to do it. You should set up virtual hosts and set the webroot to separate folders.
Create a virtual host file for each site. And write an include statement for the entire directory in your httpd config.
Example of a virtual host file:
<VirtualHost *:80>
ServerName domainname.com
DocumentRoot /var/www/vhosts/domainname.com
<Directory /var/www/vhosts/domainname.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
CustomLog /var/log/httpd/domainname.com-access.log combined
ErrorLog /var/log/httpd/domainname.com-error.log
LogLevel warn
</VirtualHost>
This will separate your error logs by domain

you don't have permission to access [custom alias] on this server

can anyone help with a following issue:
I am using wamp to run projects in my chrome browser.
after adding a newAlias which points to my project directory c:/dev/myProject
I am getting Forbidden message: you don't have permission to access /newAlias on this server.
I can access default Aliases such as phpmyadmin, webgrind...
but i cannot access my own.
I am using WampServer Version 2.5 64bit on Win 8.1 64bit located in c:/wamp.
I tried basic stuff from the net but with no luck.
Any suggestions?
Edit: content of newAlias:
Alias /bs1/ "c:/_DEV_/git/NewProject/www/"
<Directory "c:/_DEV_/git/NewProject/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
Dont change that section of your httpd.conf. Those few lines control access to the root folder of the drive that Apache is installed on. So you just gave full access to anybody with a handy hack.
The process of securing the access via Apache is to deny all access to everything from the root folder and below, and then selectively allow access for specific sites to specific areas/folders of the drive.
A better solution would be to change httpd.conf back to how it was and make the change in your Alias definition. Like this :-
Alias /bs1 "c:/_DEV_/git/NewProject/www/"
<Directory "c:/_DEV_/git/NewProject/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require local <-- to develop on this PC
Require ip 192.168.1 <-- to access the server from another PC on your network
Require all granted <-- to allow the world to see the beauty of your site
</Directory>
It is actually a better idea to use Virtual Hosts to control each site and not Alias's.
Here is a why and Howto :- WAMPServer 2.5 The Homepage, Your Projects Menu and the need for Virtual Hosts
I've updated WAMP from 2.2.22 to 2.4.9 and found that new aliases didn't work (same error message as yours).
Checking the default aliases like phpmyadmin, I've found this:
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.1.14/"
# to give access to phpmyadmin from outside
# replace the lines
#
# Require local
#
# by
#
# Require all granted
#
<Directory "c:/wamp/apps/phpmyadmin4.1.14/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
</IfDefine>
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</Directory>
If you see the contents of the file you'll notice the <IfDefine APACHE24> and <IfDefine !APACHE24> conditionals. So I've changed my alias .conf file from:
Alias /svn "c:/work/website-svn/"
<Directory "c:/work/website-svn/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
to:
Alias /svn "c:/work/website-svn/"
<Directory "c:/work/website-svn/">
Options Indexes FollowSymLinks MultiViews
Require local
</Directory>
That solved my problem, I hope it solves yours.
I am no expert on this but the answer above seemed like I was granting access to my entire computer...So tried modifying the above answer to only giving access to where my alias folder is...
So instead...Go to the httpd.conf file...and do a search for...
<Directory />
AllowOverride none
Require all denied
</Directory>
and below that add the following
<Directory "c:/path-to-your-alias-folder...">
AllowOverride none
Require all granted
</Directory>
This worked to me and I think it might be a bit safer...Again I am no expert here...Just trying to make it work...
for allow permission for your server & wamp you require 3 steps please ensure these 3 things after that you can access your site from other network with ip address e.g http://192.168.1.1/yoursitefoldername
(192.168.1.1 is you computer or vps ip address "yoursitefoldername" is folder name of your site which should be in your wamp->www folder)
1.
first of all
Port 80 and 443 must be allow for both TCP and UDP packets. To do this, create 2 inbound rules for TPC and UDP on Windows Firewall for port 80 and 443.
(or you can disable your whole firewall for testing but permanent solution if allow inbound rule)
2.
If you are using WAMPServer 3 See bottom of answer
For WAMPServer versions <= 2.5
You need to change the security setting on Apache to allow access from anywhere else, so edit your httpd.conf file.
Change this section from :
# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
To :
# onlineoffline tag - don't remove
Order Allow,Deny
Allow from all
if "Allow from all" line not work for your then use "Require all granted"
then it will work for you.
WAMPServer 3 has a different method
In version 3 and > of WAMPServer there is a Virtual Hosts pre defined for localhost so dont amend the httpd.conf file at all, leave it as you found it.
Using the menus, edit the httpd-vhosts.conf file.
It should look like this :
<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp/www
<Directory "D:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Amend it to
<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp/www
<Directory "D:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Hopefully you will have created a Virtual Host for your project and not be using the wamp\www folder for your site. In that case leave the localhost definition alone and make the change only to your Virtual Host.
3.
Dont forget to restart All Services of Wamp or Apache after making this change
I found a solution which worked for me.
In httpd.conf i changed:
<Directory />
AllowOverride none
Require all denied
</Directory>
to
<Directory />
AllowOverride none
Require all granted
</Directory>
Which solved the issue and allowed me to access my custom aliases.
I would suggest that you consider setting up virtual hosts instead. It takes a few more minutes, but it's more bulletproof. RiggsFolly's answer to a similar question is excellent in its detail, rigor, and utility:
Project Links do not work on Wamp Server

How to get rid of the public path in laravel on wamp

I have a quick issue. I am trying to use Laravel for the first time. To do so, I'm using Wamp. And I don't know if this is important, but I set the DocumentRoot of wamp at this address :
DocumentRoot "C:\Users\Bebop\Documents\Site Internet/"
I using wamp for a lot of different websites in a folder called Sites. When I access to one of the site I go to : localhost/Sites/thewebsite. So really what I want is just to get rid of the public folder in the path to the Laravel website.
For the moment I've did :
Change httpd.conf of apache to include vhosts.conf :
Include conf/extra/httpd-vhosts.conf
Created a new Virtual hosts and configured the directory like so :
DocumentRoot "C:/Users/Bebop/Documents/Site Internet/Sites/LaravelTest/public"
ServerName Sites/LaravelTest
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
After that I added a new host in the file located at C:\Windows\System32\drivers\etc
127.0.0.1 localhost
127.0.0.1 Sites/LaravelTest
By doing this, when I go to localhost I get redirected to the Laravel websites. But I would like to go to localhost/Sites/LaravelTest, because now I can't access to all my other websites.
Does anyone know how to do that ?
Thanks a lot for your help
Assuming that you want to reach your Laravel site at: http://localhost/LaravelSite/
You can either use an alias in your httpd.conf file:
Alias /LaravelSite/ "C:/Users/Bebop/Documents/Site Internet/Sites/LaravelTest/public/"
<Directory "C:/Users/Bebop/Documents/Site Internet/Sites/LaravelTest/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
or, create a symbolic link under command-prompt with the following:
mklink /D "C:\Users\Bebop\Documents\Site Internet\Sites\LaravelSite" "C:\Users\Bebop\Documents\Site Internet\Sites\LaravelTest\public"`

Django + mod_wsgi: Can someone advise me on my setup and rewrite rules

This is my first time deploying Django to a recently acquired Linode server and I'm curious if someone can look over my deployment and help me fix some nagging issues and advise me whether i'm doing things incorrectly.
Directory Structure
home\
-public\
-example.com\
-public\
-.htaccess
-index.html
-log\
-application\
-mysite\
-mysite\
-manage.py
-static\
-myapp\
-logs\
How is this for deployment structure for Django?
Incorrect URL Naming
I've hosted the Django application called 'myapp' on my domain 'example.com'. Following the instructions on the Django website I've made it so that the urls.py for the app must begin with '/myapp'. This has resulted in the domain for the app becoming 'example.com/myapp'.
How can I set it so that example.com is simply the Django app I've written?
I'd like to simply navigate to example.com and it load my app instead of example.com/myapp.
Even weirder is that I would've thought that example.com would load my index.html file however it tries to find a URL mapping for Django instead...
Django Log File Writing Permissions
Whenever I SSH onto my machine to either 'syncdb' or 'collectstatic', the logging module creates the log file I've named in my settings.py file. This causes problems for me because I am the owner of the file and apache2 (www-data) cannot write to it. It's just annoying having to manually delete the log file after every command before I restart the apache server.
Here is my /etc/apache2/sites-available/example.com file:
# domain: example.com
# public: /home/setheron/public/example.com/
WSGIPythonPath /home/setheron/public/example.com/applications/mysite:/home/setheron/env/lib/python2.7/site-packages
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin setheron#setheron.com
ServerName www.example.example.com
ServerAlias example.com
WSGIScriptAlias / /home/setheron/public/example.com/applications/mysite/mysite/wsgi.py
Alias /static/ /home/setheron/public/example.com/applications/mysite/static/
<Directory /home/setheron/public/example.com/applications/mysite/static/>
Order deny,allow
Allow from all
</Directory>
<Directory /home/setheron/public/example.com/applications/mysite/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/setheron/public/example.com/public
# Log file locations
LogLevel warn
ErrorLog /home/setheron/public/example.com/log/error.log
CustomLog /home/setheron/public/example.com/log/access.log combined
</VirtualHost>
If you want Django serving the entire site, get rid of your public directory, indexes and whatnot. Other than /static, you should only need your WSGIScriptAlias directive. Fix the urls.py to say that your site should be coming from /, rather than /myapp.

Django AND .htaccess rewrites/redirects, is this possible?

Is it possible to have Apache htaccess rewrites take effect before it hits django?
I want to be able to specify RewriteRules in an htaccess file that take precedence over django, and if nothing matches then it gets dispatched to mod_wsgi/django.
We're using apache2 with mod_wsgi and the apache vhost looks like this:
<VirtualHost *:80>
DocumentRoot /usr/local/www/site/static
Alias /css/ /usr/local/www/site/static/css/
Alias /js/ /usr/local/www/site/static/js/
Alias /img/ /usr/local/www/site/static/img/
Alias /flash/ /usr/local/www/site/static/flash/
<Directory /usr/local/www/site/static>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess mallorca-site threads=15
WSGIScriptAlias / /usr/local/www/site/config/dev/dev.wsgi
</VirtualHost>
Thanks
First off you are missing WSGIProcessGroup directive. Without that your application isn't going to be running in daemon mode as you possibly expect after having defined WSGIDaemonProcess directive.
Secondly, a .htaccess file isn't even going to be consulted when using WSGIScriptAlias except for the static directories you mapped with Alias directives.
What you need to do is use AddHandler method for mounting WSGI application, with associated rewrite rules to get it to appear at root of site, as documented in:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive
You can use an Include to include an access file into your config file, but because the directory structure only exists in urls.py, you wouldn't be able to use a .htaccess file. You can always name your include file .htaccess, but including it inside your VirtualHost is probably the best option.
I don't see why you want to do this in an .htaccess file. You should do it in the virtual host configuration you have pasted above.