Django on Debian - django

so I use Debian 6.0.9 (squeeze).
I have my project that I coded locally, that I uploaded on my server in /home/project/
now I already have mysql, apache2.2.16 and a lot of different PHP websites hosted.
Here's a typical sites-enabled/* I use :
<VirtualHost *:80>
ServerName project.com
ServerAlias www.project.com
DocumentRoot /var/www/project.com/htdocs/
</VirtualHost>
I installed wsgi mod and tried following what it says here https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/
and nothing works. I don't get how it could work anyway since I don't precise the URL I want to use for my project. The Documentation is really not clear... Anyone have a clue what I am supposed to do?
Edit : I forgot to write how my file looks like:
<VirtualHost *:80>
ServerName project.com
ServerAlias project.com
DocumentRoot /var/www/project.com/htdocs
WSGIScriptAlias / /home/project/project/wsgi.py
<Directory /home/project/project>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /var/www/project.com/htdocs/robots.txt
Alias /favicon.ico /var/www/project.com/htdocs/favicon.ico
Alias /images /var/www/project.com/htdocs/images
Alias /static /var/www/project.com/htdocs/static
ErrorLog /var/www/project.com/logs/error.log
CustomLog /var/www/project.com/logs/access.log combined
</VirtualHost>

In your VirtualHost def:
Make sure you configure:
DocumentRoot, WSGIScriptAlias - configured properly is a MUST
ErrorLog, CustomLog - it helps in debugging
WSGIDaemonProcess and WSGIProcessGroup - is a good security practice
For example:
WSGIPythonHome PATH_TO_YOUR_PYTHON
<VirtualHost *:80>
ServerName project.com
ServerAlias www.project.com, *.project.*
ErrorLog "/var/log/httpd/vhost_test_error.log"
CustomLog "/var/log/httpd/vhost_test_access.log" combined
WSGIDaemonProcess project processes=2 threads=15 display-name=%{GROUP} python-path=PATH_TO_YOUR_VIRTUAL_ENV
WSGIProcessGroup project
#DocumentRoot /var/www/project.com/htdocs/
DocumentRoot "/var/www/project.com/PATH_TO_DJANGO_PROJECT"
WSGIScriptAlias / /var/www/project.com/PATH_TO_DJANGO_PROJECT/wsgi.py
</VirtualHost>

Related

Serving multiple domains with Django and Apache maps to one location only

I am attempting to setup Django to serve multiple sites (in the below configuration I am using examples www.domain1.com and www.domain2.com). I have installed Apache2 successfully, configured wsgi.py successfully (or so it seems).
I have built my appache configuration file to attempt the following mapping:
www.example1.com to serve from /var/www/mysite1
www.example2.com to serve from /var/www/mysite2
DNS A records for both example1.com and example2.com point to the same IP address.
The trouble with my setup as it exists is that both domain1.com and domain2.com map to the Django residing at /var/www/mysite1, despite the fact that I have (in theory) set them to map to their respective locations.
My apache config files are as follows, and both of the files (mysite1.conf and mysite2.conf) have had symlinks made for them using a2ensite:
#/etc/apache2/sites-available/mysite1.conf
WSGIDaemonProcess mysite processes=2 threads=25 python-home=/var/www/mysite1/myenv1 python-path=/var/www/mysite1/myenv1/mys
ite1
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite1/myenv1/mysite1/mysite1/wsgi.py
<VirtualHost *:80>
ServerName domain1.com
ServerAlias xx.xx.xx.xx
DocumentRoot /var/www/mysite1
ErrorLog ${APACHE_LOG_DIR}/mysite1-error.log
CustomLog ${APACHE_LOG_DIR}/mysite1-access.log combined
Alias /robots.txt /var/www/mysite1/myenv1/mysite1/static/robots.txt
Alias /favicon.ico /var/www/mysite1/myenv1/mysite1/static/favicon.ico
Alias /static/ /var/www/mysite1/myenv1/mysite1/static/
<Directory /var/www/mysite1/myenv1/mysite1/mysite1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite1/myenv1/mysite1/static>
Require all granted
</Directory>
</VirtualHost>
#/etc/apache2/sites-available/mysite2.conf
WSGIDaemonProcess mysite2 processes=2 threads=25 python-home=/var/www/mysite2/myenv2 python-path=/var/www/mysite2/myenv
2/mysite2
WSGIProcessGroup mysite2
WSGIScriptAlias / /var/www/mysite2/myenv2/mysite2/mysite2/wsgi.py process-group=mysite2
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName domain2.com
ErrorLog ${APACHE_LOG_DIR}/mysite2-error.log
CustomLog ${APACHE_LOG_DIR}/mysite2-access.log combined
DocumentRoot /var/www/mysite2
Alias /robots.txt /var/www/mysite2/myenv2/mysite2/static/robots.txt
Alias /favicon.ico /var/www/mysite2/myenv2/mysite2/static/favicon.ico
Alias /static/ /var/www/mysite2/myenv2/mysite2/static/
<Directory /var/www/mysite2/myenv2/mysite2/mysite2>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite2/myenv2/mysite2/static>
Require all granted
</Directory>
</VirtualHost>
An example wsgi.py file looks as below, and is working correctly (ie loading from the correct location) when it does load:
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite1.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite1.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
There are no errors being reported in either logs (/var/syslog/apache2/mysiteX.conf where x=1 or 2)
What am I doing wrong? How can I correct this so that domain2 starts to map to /var/www/mysite2?
Many thanks in advance!
The WSGI tags need to be inside the VirtualHost block for their respective domain names.
E.g.
<VirtualHost *:80>
ServerName domain1.com
ServerAlias xx.xx.xx.xx
DocumentRoot /var/www/mysite1
WSGIDaemonProcess mysite processes=2 threads=25 python-home=/var/www/mysite1/myenv1 python-path=/var/www/mysite1/myenv1/mys
ite1
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite1/myenv1/mysite1/mysite1/wsgi.py
...
</VirtualHost>

Django project set up with Apache2 - i want to access it through I.P/application_name/

Hi I want to set up my django project to be access through apache2 by I.P/application_name/
So "192.0.0.0/app/" (Ip being an example)
Here is my 000-default.conf file in etc/apache2/sites-available
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess HTSv2 python-home=/home/django/config/env python-path=/usr/local/django/app
WSGIProcessGroup HTSv2
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
<Directory /usr/local/django/app/application>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /usr/local/django/app/static/
<Directory /usr/local/django/app/static>
Require all granted
</Directory>
<Directory /usr/local/django/app>
Deny from all
Allow from ...
</Directory>
</VirtualHost>
When I change the line:
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
to
WSGIScriptAlias /app/ /usr/local/django/app/application/wsgi.py
I can access the home page of my application by 192.0.0.0/app/
However when I click on any buttons, obviously does not keep to this, so for example going to page1, does not go to 192.0.0.0/app/page1, it goes to 192.0.0.0/page1
How can I configure apache2 to do this? The reason I want to do this is so I can host multiple projects on the same server, so the root of 1 project is 192.0.0.0/app1/ and then the root of the other is 192.0.0.0/app2/ etc...

Setting-up localhost to other desired name on WAMP 2.4.9 server gets 404 Error

I want to rename my localhost server to other name, however I have encountered a 404 error. I have followed the steps how to set this up, But still I get error. I wonder what's wrong. I will provide the changes done.
c:\Windows\System32\Drivers\Etc\hosts.file
127.0.0.1 localhost
127.0.0.1 bluescript.com.ph
::89 localhost
::89 bluescript.com.ph
c:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhost.conf
I added the third host on the file
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName bluescript.com.ph
DocumentRoot "c:/wamp/www/bluescript/"
<Directory "c:/wamp/www/bluescript/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Under httpd.conf i did changed my port to 8989, since skype will use port 80
ServerName localhost:8989
#Listen 12.34.56.78:8989
Listen 0.0.0.0:8989
Listen [::0]:8989
I've already restarted WAMP and re-open the web browser and type url: http://bluescript.com.ph and get error: HTTP Error 404. The requested resource is not found. Where did i go wrong?
1) Remove these dummy (Example) Virtual Hosts that point to non existing folders
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
2)
If you must use a Non-Standard port number for Apache then that port number needs to be on the Virtual Host as well.
You should also add a Virtual Hosts for localhost
<VirtualHost *:8989>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:8989>
ServerName bluescript.com.ph
DocumentRoot "c:/wamp/www/bluescript/"
<Directory "c:/wamp/www/bluescript/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Also remember to remove the comment from httpd.conf to activate the httpd-vhosts.conf file
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Now restart Apache
And of course this means you must use the Non-Standard port number on all your urls. Like
http://bluescript.com.ph:8989
3)
Also this is wrong in your hosts file! Port number are not used in this file, so
::89 localhost
::89 bluescript.com.ph
Should be
::1 localhost
::1 bluescript.com.ph
After this change either reboot, or from a command window launched "As Adminitrator" do
net stop dnscache
net start dnscache

VirtualHost configuration doesn't allow second website to run

I have this in my /etc/apache2/sites-available/staginnx.com.conf
WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
WSGIPythonPath /home/ubuntu/v1/staginnx-info/app/website
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin info#staginnx.com
ServerName staginnx.com
ServerAlias www.staginnx.com
<Directory /home/ubuntu/v1/staginnx-info/app/website/website>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/
<Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
Require all granted
</Directory>
Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico
ErrorLog /var/log/apache2/error.log
</VirtualHost>
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin blog.staginnx#staginnx.com
ServerName blog.staginnx.com
ServerAlias blog.staginnx.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/html/blog/
<Directory /var/www/html/blog>
Require all granted
</Directory>
# Custom log file locations
LogLevel warn
ErrorLog /var/www/html/blog/log/error.log
CustomLog /var/www/html/blog/log/access.log combined
</VirtualHost>
Now the first one, the main website is working fine. The second one, BLOG is not working.
I have done sudo a2ensite staginnx.com.conf and a symlink is generated at sites-enabled. I have done reload apache and restart too.
Surfed around but no luck.
Want to install wordpress blog in my blog folder.
In order to use your django application inside a virtual host you need to set the WSGIScriptAlias inside the virtualhost settings and also you can't use the WSGIPythonPath, you need to use WSGIDaemonProcess like in the following settings.
<VirtualHost *:80>
WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
WSGIDaemonProcess example.com python-path=/home/ubuntu/v1/staginnx-info/app/website
# Admin email, Server Name (domain name) and any aliases
ServerAdmin info#staginnx.com
ServerName staginnx.com
ServerAlias www.staginnx.com
<Directory /home/ubuntu/v1/staginnx-info/app/website/website>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/
<Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
Require all granted
</Directory>
Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico
ErrorLog /var/log/apache2/error.log
</VirtualHost>
Also in case you want to host multiple application on the same host then you need to change a small setting in the wsgi.py file as well.
instead of using
os.environ.setdefault(DJANGO_SETTINGS_MODULE, "app.settings")
you should use
os.environ["DJANGO_SETTINGS_MODULE"] = "app.settings"
I hope this helps you.
For WSGIDaemonProcess setting

Deploying multiple django projects on apache with mod_wsgi

I'm trying to deploy 2 django projects on Apache with mod_wsgi using daemon mode, but right now I just get 404's when I try to load the pages.
The two sites are hosted on the same server, both on port 80. The two entries in sites-avalable are below:
<VirtualHost *:80>
ServerAdmin admin#site1.com
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/site1.com
ErrorLog /srv/www/site1.com/logs/error.log
CustomLog /srv/www/site1.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.org
ServerName site2.org
ServerAlias www.site2.org
DocumentRoot /var/www/site2.org
ErrorLog /srv/www/site2.org/logs/error.log
CustomLog /srv/www/site2.org/logs/access.log combined
</VirtualHost>
And in my httpd.conf,
WSGIDaemonProcess site1.com python-path=/usr/local/www/site1/
WSGIProcessGroup site1.com
WSGIScriptAlias site1.com/blog /usr/local/www/site1/site1/wsgi.py
WSGIDaemonProcess site2.org python-path=/usr/local/www/site2/
WSGIProcessGroup site2.org
WSGIScriptAlias site2.org/ /usr/local/www/site2/site2/wsgi.py
<Directory /usr/local/www/site1/site1>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /usr/local/www/site2/site2>
<Files wsgi.py>
Order deny, allow
Allow from all
</Files>
</Directory>
I took the httpd.conf stuff right out of the Django docs, but it's still not working properly. site1.com/blog gives me a 404, and site2.org gives me a generic Apache filetree. What am I missing here?
If you have a sites-available directory, you're on a Debian-derived distro, and you shouldn't be editing httpd.conf at all. All the stuff that you've put into httpd.conf should go in the relevant files in sites-available.