i use an apache to run my django instances.
my apache doubles the django output.
so in developement i get this:
my response text
but on apache "production", this:
my response text
my response text
my vhost config look like this:
<VirtualHost *>
Alias /public /xxx/public
Redirect /robots.txt /public/robots.txt
<Directory "/xxx">
Order allow,deny
Allow from all
</Directory>
ServerName www.xxx.de
ServerAlias *.xxx.de
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE '/tmp/python-eggs'
PythonHandler django.core.handlers.modpython
PythonDebug Off
PythonPath "['', '/xxx'] + sys.pa
</VirtualHost>
i don't know whats wrong, do u know?
I do not know whether this is the issue, but you have PythonHandler written twice.
Also, mod.wsgi is preferred to mod_python by many.
Related
I have this configuration in at the end of my httpd.conf:
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapp.settings
PythonOption django.root /
PythonDebug On
PythonPath "['/my/path] + sys.path"
</Location>
This allows my application to startup, but the static files are not being served. I was thinking of adding something like this:
<Location "/site_media">
# what to add here?
</Location>
And tell Apache to serve files from /site_media/... from /my/path/myapp/media. However, I cannot find a way to make the connection between /site_media and the actual path to my media directory. Could you guide me?
EDIT: I added this to httpd.conf:
Alias /site_media /my/path/myapp/media
<Directory /my/path/myapp/media>
Order allow,deny
Allow from all
</Directory>
<Location "/site_media">
</Location>
But, Apache still gives me 404 errors. I also tried to add a SetHandler None inside the /site_media/ location element, but I still receive the same 404 error codes.
Alias, but read the full section.
How do i run Django and phpmyadmin on apache webserver. I used localhost/phpmyadmin and it worked but after i configured Django on localhost/admin, phpmyadmin is not working i get an error page from Django saying the URL is not in urls.py. is there a way to run Django on port 81(httpd.conf) so that it will not conflict with phpmyadmin, or is there something else i am missing.I use mod_python module.This is my httpd.conf file when i change the location "/" to location "/home/projects/" Phpmyadmin works but Django fails and viceversa
<location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE hana.settings
PythonPath "['/home/projects/', '/home/projects/mysite', '/home/projects/mysite/mysite'] + sys.path"
</location>
<location "/admin-media">
SetHandler None
</location>
You can run them both on same port. Just add these lines to your apache config after WSGIAlias directive:
Alias /phphmyadmin /sys/path/to/phpmyadmin
<Location /phphmyadmin>
SetHandler None
</Location>
You can also run them on different ports.
Listen 80
Listen 81
NameVirtualHost *:80
NameVirtualHost *:81
<VirtualHost *:81>
django-config
</VirtualHost>
<VirtualHost *:80>
phph-my-admin-configs
</VirtualHost>
Now I have apache configuration which works only with localhost domain (http://localhost/).
Alias /media/ "/ścieżka/do/instalacji/django/contrib/admin/media/"
Alias /site_media/ "/ścieżka/do/plikow/site_media/"
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonPath "['/thomas/django_projects/project'] + sys.path"
PythonDebug On
</Location>
<Location "/site_media">
SetHandler none
</Location>
How can I make it working for some subdomains like pl.localhost or uk.localhost? This subdomains should display the same page what domain (localhost).
Second question: It is possible change default localhost address (http://localhost/) to (http://localhost.com/) or (http://www.localhost.com/) or something else?
I want to set up test and production versions of a Django app on separate apache name virtual hosts and wanted to know the best way to do this.
Here's what I've done, and it seems to work ok, but I'm wondering if there's a better way.
<VirtualHost *>
ServerName test.foo.bar
<Location "/app/">
SetHandler python-program
PythonPath "['/home/jdm/django-apps/xyz/test/'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /app
PythonDebug On
PythonInterpreter test
</Location>
</VirtualHost>
<VirtualHost *>
ServerName live.foo.bar
<Location "/app/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "['/home/jdm/django-apps/xyz/live/'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /app
PythonDebug On
PythonInterpreter live
</Location>
</VirtualHost>
The apps live in /home/jdm/django-apps/xyz/live/ and /home/jdm/django-apps/xyz/test/. The apps are at http://live.foo.bar/app/ and http://test.foo.bar/app/
I think virtualenv is what you need.
Have django serving different settings file & database based on subdomains. The virtual host entries are manually added to apache.
There are currently two subdomains with different databases. First one is working okay, the second one is not displaying any css/images.
Apache configuration is as, there are two of them
<VirtualHost *:80>
ServerName test.domain.com
ServerAlias test.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</VirtualHost>
The content of subdomain having issues with displaying css/images , are in /public/media folder. If accessed directly via http://test.domain.com/public/media/images/image.jpg , the images are there.
1) Note that you are not loading the default "settings.py", but "settings/test.py".
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
So maybe it should be:
SetEnv DJANGO_SETTINGS_MODULE site.settings
or
SetEnv DJANGO_SETTINGS_MODULE site.settings.production
2) Make sure you have this, in whatever your settings file is:
DEBUG = False
MEDIA_URL = "/public/media"
ADMIN_MEDIA_PREFIX = "/public/admin_media"
I suggest you uses two different virtualhosts for the two different subdomains.
Subdomain test1.domain.com
ServerName test1.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</VirtualHost>
Subdomain test2.domain.com
ServerName test2.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</VirtualHost>
It was session/cookie problem. Added SESSION_COOKIE_DOMAIN to settings.py with subdomain , seems to work fine now.