how can i resolve the default apache page for django with apache - django

im new at deploying and i've been trying to deploy my django app and i can only seem to get the default :"it works" page to work. i have followed a few tutorials to no luck.
my '/etc/apache2/sites-available/37.***.22.**' Virtual host:
`<VirtualHost *:80>
ServerAdmin webmaster#37.***.22.**
ServerName 37.***.22.**
DocumentRoot /var/www/37.***.22.**/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/37.***.22.**/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
WSGI file:
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/myprojectenv/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('~/MyProject/django-bookmarks')
sys.path.append('~/MyProject/django-bookmarks/django_bookmarks')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_bookmarks.settings'
# Activate your virtual env
activate_env=os.path.expanduser("~/.virtualenvs/myprojectenv/bin/activate_this.$
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
i had SCP'ed my files for my djagno app into the MyProject dir on the server.
i also ran the a2ensite 37.***.22.25 and restarted apache, but even with that i still get the "it works" default page. how can i resolve this?
i had also installed Postfgress. i really want to deploy this app asap and have been struggling, and learning alot also at the same time! any advise would be appreciated.
thanks in advance.

Make sure that you have mod_wsgi installed and enabled for Apache.
You will also want to ensure that you have defined both WSGIProcessGroup and WSGIScriptAlias (configuration directives for mod_wsgi) for the virtual host.

Related

can't run a django project with apache on a subdomain

I have an online shop which contains a main page and a shop page. now this main page and shop page are actually two different projects, so in order to have them online, I have to run two instances of django.
now the things is, i want to have the main page on www.setakshop.ir, and the shop on shop.setakshop.ir. The thing is, after setting up the necessary settings, both shop.setakshop.ir and setakshop.ir point to the main page! and I can only see the shop page through setakshop.ir:8000, which I expected apache to proxy it to shop.setakshop.ir
I serve the DNS myself and here are my DNS settings:
;
; BIND data file for setakshop.ir
;
$TTL 3h
# IN SOA ns1.setakshop.ir. admin.setakshop.ir. (
1 ; Serial
3h ; Refresh after 3 hours
1h ; Retry after 1 hour
1w ; Expire after 1 week
1h ) ; Negative caching TTL of 1 day
;
# IN NS ns1.setakshop.ir.
# IN NS ns2.setakshop.ir.
setakshop.ir. IN MX 10 mail.setakshop.ir.
setakshop.ir. IN A xx.xx.xx.xx
ns1 IN A xx.xx.xx.xx
ns2 IN A xx.xx.xx.xx
www IN CNAME setakshop.ir.
mail IN A xx.xx.xx.xx
ftp IN CNAME setakshop.ir.
shop IN A xx.xx.xx.xx
and when run
nslookup shop.setakshop.ir
i get a valid response. So I think the DNS setup is actually fine.
Now the other thing I suspect, is my apache settings. I suspect that I haven't set the proxy settings right. here it is:
<VirtualHost *:80>
WSGIDaemonProcess main python-path=/var/www/setak:/var/www/setak/setakenv/lib/python2.7/site-packages
WSGIProcessGroup main
WSGIScriptAlias / /var/www/setak/setakenv/main/ashop/ashop/ashop/wsgi.py
ServerAdmin admin#setakshop.ir
ServerName www.setakshop.ir
ProxyPass / http://www.setakshop.ir:8001/
ProxyPassReverse / http://www.setakshop.ir:8001/
Alias /media/ /var/www/setak/setakenv/main/ashop/ashop/static/media/
Alias /static/ /var/www/setak/setakenv/main/ashop/ashop/static/
<Directory /var/www/setak/setakenv/main/ashop/ashop/static>
Order allow,deny
allow from all
</Directory>
<Directory /var/www/setak/setakenv/main/ashop/ashop/static/media>
Order allow,deny
allow from all
</Directory>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *:8080>
WSGIDaemonProcess setak python-path=/var/www/setak:/var/www/setak/setakenv/lib/python2.7/site-packages
WSGIProcessGroup setak
WSGIScriptAlias / /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/wsgi.py
ServerAdmin admin#setakshop.ir
ServerName shop.setakshop.ir
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://shop.setakshop.ir:8000
ProxyPassReverse / http://shop.setakshop.ir:8000
Alias /robots.txt /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/static/robots.txt
Alias /media/ /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/media/
Alias /static/ /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/static/
<Directory /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/static>
Order allow,deny
allow from all
</Directory>
<Directory /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/media>
Order allow,deny
allow from all
</Directory>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Now I dont get what I'm doing wrong here!
I run both the projects with the following command :
./manage.py runserver 0.0.0.0:8000
./manage.py runserver 0.0.0.0:8001
Can anybody tell me what I'm doing wrong?
thanks in advance.
That really is not how you run Django applications via Apache. runserver is not designed for or appropriate for production; it makes no sense to use Apache as a reverse proxy to runserver.
Confusingly it seems that you have correctly set up WSGIScriptAlias for one of your sites, but you are still proxying it. You need to remove the proxy stuff altogether, forget about runserver, and use mod_wsgi throughout.
The way to get Apache to serve two sites on two domains is to use NamedVirtualHosts. You simply set up two separate ones, each with the correct server name.
First of all you should not use ./manage.py runserver along with apache and you should not use ./manage.py runserver when you move your website to production. runserver is only for development environment, it can handle only one request at a time.
You should use mod_wsgi for running your project using Apache. Look the docs here
Or else gunicorn and nginx can be used for running your project. Have a look at this.

Configuring Apache with Django

I'm trying to configure Apache with Django. Everything is working except the admin panel. It's static files are not loading. The documentation talks about different ways of doing it but none are working for me.
Here is my 0000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin maahd#meddy.co
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Alias /static /var/www/html/sp-django-master/meddy1/static
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
include sites-available/meddy.co.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Here is my meddy.co.conf where meddy.co is my website:
<VirtualHost *:80>
ServerName ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com
ServerAlias www.ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com
WSGIScriptAlias / /var/www/html/sp-django-master/meddy.wsgi
DocumentRoot /var/www/html/sp-django-master
#Alias /static /var/www/html/sp-django-master/meddy1/static
<Location "/static/">
Options -Indexes
</Location>
#AliasMatch ^/([^/]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1
AliasMatch ^/([^/meddy1]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1
AliasMatch ^/([^/admin]*\.css) /var/www/html/sp-django-master/static/admin/css/$1
Alias /static/ /var/www/html/sp-django-master/meddy1/static/
<Directory /var/www/html/sp-django-master/meddy1/static>
Require all granted
</Directory>
<Directory /var/www/html/sp-django-master/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /var/www/html/sp-django-master/uploads/
<Directory /var/www/html/sp-django-master/uploads>
Require all granted
</Directory>
Alias /static/admin/ /var/www/html/sp-django-master/static/admin/
</VirtualHost>
Any help would be appreciated.

Deploy a Django site and a PHP site on the same server with Apache and mod_wsgi

I currently have a Django site working at cinepass.com.ec , I would like to deploy an additional PHP site to the same server at mobile.cinepass.com.ec
My current httpd.conf (from DjangoFoo) :
<Directory "/home/ec2-user/cinepass/media">
Order deny,allow
Allow from all
</Directory>
<Directory "/home/ec2-user/cinepass/cinepass">
AllowOverride All
Order deny,allow
Allow from all
</Directory>
Alias /media/ /home/ec2-user/cinepass/media/
ServerAdmin smansfield#palapa.com.ec
ErrorLog "logs/cinepass.com-error_log"
CustomLog "logs/cinepass.com-access_log" common
# mod_wsgi configuration is here
# we are running as user/group 'deamon', if you don't have those you need to change or create.
WSGIDaemonProcess cinepass python-path=/home/ec2-user/cinepass:/home/ec2-user/cinepass/venv/lib/python2.6/site-packages user=daemon group=daemon processes=2 threads=25
WSGIProcessGroup cinepass
# this is our WSGI file.
WSGIScriptAlias / /home/ec2-user/cinepass/cinepass/wsgi.py
My current wsgi.py :
import os, sys
sys.path.append('/home/')
sys.path.append('/home/ec2-user/cinepass/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cinepass.settings_production.py")
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
How would I edit my Apache configuration so that I can also run a php site at mobile.cinepass.com.ec?
Using apache´s virtualhosts, here I put an example of something similar in a server of mine, in which I have a djangp app in the main domain and a joomla in a subdomain. Both files are located in /etc/apache2/sites-enabled
Joomla´s apache conf file (named /etc/apache2/sites-enabled/manual.domain.com):
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin dsanabria#domain.com
ServerName manual.domain.com
DocumentRoot "/home/ubuntu/manual/"
<Directory /home/ubuntu/manual/>
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/log/apache2/manual.domain-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/apache2/manual.domain-access.log combined
</VirtualHost>
And the django app (named /etc/apache2/sites-enabled/www.domain.co):
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin diego#diegue.us
ServerName domain.co
ServerAlias machete.anotherdomain.com
Alias /admin/media/ /home/ubuntu/webapps/machete/lib/python2.7/site-packages/grappelli/media/
Alias /media/ /home/ubuntu/webapps/machete/machete/media/
Alias /static/ /home/ubuntu/webapps/machete/machete/collected/
<Directory /home/ubuntu/webapps/machete/lib/python2.7/site-packages/grappelli/media/>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ubuntu/webapps/machete/lib/python2.7/site-packages/django/contrib/admin/media/ >
Order deny,allow
Allow from all
</Directory>
<Directory /home/ubuntu/webapps/machete/machete/media/>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ubuntu/webapps/machete/machete/collected/>
Order deny,allow
Allow from all
</Directory>
WSGIScriptReloading On
WSGIDaemonProcess machete python-path=/home/ubuntu/webapps/machete/lib/python2.7/site-packages
WSGIProcessGroup machete
WSGIApplicationGroup machete
WSGIPassAuthorization On
WSGIScriptAlias / /home/ubuntu/webapps/machete/machete/machete/wsgi.py
ErrorLog /var/log/apache2/machete-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/apache2/machete-access.log combined
</VirtualHost>
The first, tells to apache, that if the user gets to manual.domain.com, just response with a php application (joomla). The second file says to apache, that if the user calls the server with www.domain.com response with a python wsgy, (django).
This is in a ubuntu server, redhat/centos/fedora locates the folder sites-enabled in another location that I can´t remember, but anyway you can use virtualhosts.
Generraly, I avoid to mess with the httpd.conf file and prefer use virtualhosts.

running two django apps with SSL in same apache server

I have apache2 installed in ubuntu lucid ,and have enabled ssl .Now I am running a django app (lets say myapp1 )on it using mod_wsgi.
I have configured the /etc/apache2/sites_enabled/ssl file and /etc/apache2/sites-available/ssl as below.
Now I can run my app using the url
https://127.0.0.1/myapp1
I need to run another django app (say myapp2 )in the same server,and that also uses SSL.So,how should I configure it?Can somebody please help me?
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /home/me/dev/python/django/myapp1
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
WSGIScriptAlias /myapp1 /home/me/dev/python/django/myapp1/myapp1.wsgi
Alias /site_media/ /home/me/dev/python/django/myapp1/media/
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
By adding:
WSGIScriptAlias /myapp2 /home/me/dev/python/django/myapp2/myapp2.wsgi
You will need to resolve any conflict though if they can't share the same static media files. That is, have each have media in different locations and configure settings for each Django project appropriately.

Django Deployment on Apache's virtualhost

I have a wordpress (/var/www/cb), which I wish to run as root (www.cb.com) and one Django app (/vc/cb/cb) as a subdirectory (cb.com/launch).
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin info#cb.com
ServerName cb.com
DocumentRoot /var/www/cb
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/cb>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo Indexes
Order allow,deny
allow from all
</Directory>
WSGIScriptAlias /launch /vc/cb/cb/wsgi.py
<Directory "/vc/cb/cb">
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
</IfModule>
A similar question has been asked here, however that was pre-Django-1.4, where you had to create your wsgi file manually.
In the documentation it says the wsgi.py is created automatically for you. The main difference I see is the file extension, in the link above they refer to the wsgi file as xx.wsgi while django 1.4 documentation points to wsgi.py. I don't know if this is an issue, but I get a 404 when I do a https://cb.com/launch
The content of wsgi.py:
import os
import sys
sys.path.append('/vc/cb')
sys.path.append('/vc/cb/cb')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cb.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
What am I missing?