403 forbidden when Django folder is located in /root - django

I'm trying to deploy my local Django site on my Ubuntu 12.04 server. I followed a tutorial, and everything seems to work fine, except Apache won't allow me to store my Django project under /root. More specifically, I get a 403 Forbidden when trying to access my site.
I suspect I need to configure my virtual host in a different manner. Any ideas?
Here is /etc/apache2/sites-available/mysite
<VirtualHost *:80>
ServerAdmin me#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
WSGIScriptAlias / /root/me/index.wsgi
Alias /static/ /root/me/static/
<Location "/static/">
Options -Indexes
</Location>
ErrorLog /var/log/mysite/error.log
</VirtualHost>

Thanks for the comments. I'll mark this as the correct answer for future reference.
I ended up moving the whole Django project to /home/anotheruser, and defined DocumentRoot as per Aamir Adnans suggestion. After service apache2 restart it started working.

Related

Reconfiguring Apache to serve website root from new php source and specific sub-urls from old django site

How do I make a django website (in a apache/mod_wsgi/django setup) which is configured to serve from the root url, serve only for specific sub-url but not the root url? The root url shall be served from a new source (php). All this with a minimum of reconfiguration.
Currently the condensed virtualhost config looks like this
<VirtualHost *:80>
ServerAdmin admin#mysite.com
ServerName mysite.com
# mappings to django
WSGIScriptAlias / /opt/mysite/mysite.wsgi
<Directory /opt/mysite>
Order allow,deny
Allow from all
</Directory>
# mappings to wordpress
Alias /wp/ /var/www/mysiteWP/
<Location "/var/www/mysiteWP/">
Options -Indexes
</Location>
Alias /show/ /var/www/mysiteWP/
Alias /collection/ /var/www/mysiteWP/
</VirtualHost>
As you can see django and php(wordpress) are running side by side. Wordpress just serving mysite.com/show/ and mysite.com/collection/. Django is serving the rest, including the root url mysite.com. This configuration works.
What I want to do now, is, I want to make wordpress serve everything except some specific urls which should be served by django. E.g. django should just serve mysite.com/shop/ and mysite.com/news/ but nothing else, also excluding mysite.com.
How would I do this with a minimum of reconfiguration?
Thanks for your answers and hints.
Props to Graham Dumpleton. He answered another question of the exact same kind in this Q&A: Django (wsgi) and Wordpress coexisting in Apache virtualhost.
In short, after configuring Apache so the root url is served from php, the solution to route specific sub urls to django, but making it think its mount point is still the root, is WSGIScriptAliasMatch.
To this (example)problem the simple addition to the apache virtual host config was this:
WSGIScriptAliasMatch ^(/(shop|news)) /opt/mysite/mysite.wsgi$1
The whole virtual host config for this example is:
<VirtualHost *:80>
ServerAdmin admin#mysite.com
ServerName mysite.com
# mappings to django
WSGIScriptAliasMatch ^(/(shop|news)) /opt/mysite/mysite.wsgi$1
<Directory /opt/mysite>
Order allow,deny
Allow from all
</Directory>
# mappings to wordpress
DocumentRoot /var/www/mysiteWP/
<Location "/var/www/mysiteWP/">
Options -Indexes
</Location>
</VirtualHost>

Deploy Django on Apache virtual host: 404

I know there are a lot of articles talking about this issue, but I keep getting a 404 error when deploying a Django site through Apache virtual host. Here is my .conf file:
Listen 8001
<VirtualHost *:8001>
ServerName www.myhostname.com/basic
ServerAdmin caisj#example.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
DocumentRoot /home/browser/BASIC/basic
Alias /static /home/browser/BASIC/basic/static
Alias /media /home/browser/BASIC/_py/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/contrib/admin/media
WSGIScriptAlias /basic /home/browser/BASIC/basic/basic.wsgi
ErrorLog /home/browser/BASIC/basic/log/basic.error.log
LogLevel info
CustomLog /home/browser/BASIC/basic/log/basic.access.log combined
</VirtualHost>
I have tried different combinations of the "ServerName" and other parameters, but when visiting www.myhostname.com/basic, I keep getting a 404 error. The Apache restarts successfully and the log file contains no clues.
Or could anybody help to tell where to find errors? Thanks.
You have set this up to listen on port 8001 and rooted at /basic, so you need to access www.myhostname.com:8001/basic.
Note that you shouldn't set DocumentRoot to the location of your Django files. It isn't necessary to serve a Django app, and it could potentially be a security risk - a misconfiguration could mean that your code files, including any db passwords, might be served.

Django urls.py catches all existing HTML projects' urls on WampServer

I had WampServer working perfectly with Aptana IDE using multiple folders for different html projects. Then I installed Django and added this to Apache's httpd.conf:
Alias /images/ "c:/wamp/www/daas/templates/images/"
<Directory "c:/wamp/www/daas/images>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi"
<Directory "c:/wamp/www/daas/apache">
Allow from all
</Directory>
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot c:/wamp/www/daas/
</VirtualHost>
and now the virtual hosts I had for html projects...
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName projectA.local
DocumentRoot 'C:\wamp\www\projectA'
</VirtualHost>
don't load correctly because Django's urls.py is catching all urls The current URL, projectA, didn't match any of these regular expressions, even the ones not inside the Django's projects.
How can I solve this? On Djano's side or on Apache's side? Here (How do i run Django and phpmyadmin on apache webserver on ubuntu) is a similar problem but the solution didn't worked for me. And luckily localhost/phpmyadmin works correctly but localhost/projectA doesn't.
It looks like WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi" in your httpd.conf catches all requests on apache.

Django virtual host setup. Apache mod_wsgi

I am hoping there is a simple answer to my question as I am not the most experienced with python and Apache.
I am trying to hook up Apache with mod_wsgi. I have used a virtual host to do so. see below:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName testserver.com/django
#DocumentRoot /
WSGIScriptAlias / /home/mycode/mysite/scripts/django.wsgi
Alias /media/ /home/mycode/mysite/mysite/media/
Alias /adminmedia/ /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/
<Directory "/home/mycode/mysite/mysite/media">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
This works great for my django project when I go to testserver.com instead of my php index page I get my django project.
What I am looking for is help with allow my php projects in /var/www/html/ and my django projects to coexist. I am trying to make it so to reach my django project I type testserver.com/django
Any help or guidance is greatly appreciated :)
Thanks!
Change:
WSGIScriptAlias / /home/mycode/mysite/scripts/django.wsgi
to:
WSGIScriptAlias /django /home/mycode/mysite/scripts/django.wsgi
The first argument is the mount point, you have it to be the root of the web server, so just change it to '/django' instead.

Pointing subdomain to specific url in Django

I have a Django site, working on mod_wsgi and Apache. (eg, example.com) I made a subdomain (eg, info.example.com) and want to point it to app in the existing project. Is it possible, that I have one urls.py file, and example.com/info and info.example.com point to the same view in Django project (without duplicating the whole project in different directory)?
If so, how can I do it? Currently the example.com virtalhost config for the existing project looks like this:
<VirtualHost 12.34.56.78:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/Example/Pub_html
WSGIScriptAlias / /srv/www/Example/example.wsgi
<Directory /srv/www/Example/Example>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /srv/www/Example/robots.txt
Alias /favicon.ico /srv/www/Example/favicon.ico
....
</VirtualHost>
Thanks in advance!
UPDATE: I did a quick fix here by creating another Django project which shares database tables and template folder with the existing one. It works, but it's not really DRY :)
I'd do this with a reverse proxy, I reckon. If you have mod_proxy and mod_proxy_html available, try something like this:
<VirtualHost 12.34.56.78:80>
ServerName info.example.com
ProxyPass / http://example.com/info
SetOutputFilter proxy-html
<Location />
ProxyPassReverse /info/
ProxyHTMLURLMap /info/ /
</Location>
ProxyHTMLURLMap http://example.com/info /
</VirtualHost>
the details may not be quite right, so let me know if you can't get it to work.