I have a Django app set up with Apache and mod_wsgi and it's working fine. I have a Zinnia blog under the same app functioning at the /blog/ subdirectory. So, the blog is www.mysite.com/blog/. What I wanna do is have blog.mysite.com/ point to the /blog/ subdirectory. I'm stumped because I don't know if I should do this through Django or Apache. So, any ideas?
This has to be done with Apache config.
I think you have to setup a Reverse Proxy, which will listen to blog.mysite.com domain and proxy requests to www.mysite.com/blog/.
Unfortunately I'm not an Apache pro, so can't help you with configuration.
Completely from memory and can't test it right now, but in the VirtualHost for blog.mysite.com mount it as:
WSGIScriptAlias / /some/path/wsgi.py/blog
In other words, you still mount it with mod_wsgi, but add '/blog' to the end of the target WSGI script path. This should from memory cause Apache and mod_wsgi to remap things so that '/blog' automatically gets added as part of the URL seen by the Django application. Thus it should map to the blog mapped at that location in the URL namespace in the Django urls.py.
Do note that because you are doing it with a distinct WSGIScriptAlias, it will actually load up a second copy of your Django site in memory in a different sub interpreter than the first one. If that is undesirable, you can use WSGIApplicationGroup directive to override which application group they are both running in and set them to be the same. Preferably use mod_wsgi daemon mode if you aren't already and have them run distinct from the Apache child worker processes as well, as that is generally better than using embedded mode.
Related
I'm new to Django and Apache, so apologies if my terminology is a bit off.
I have a Django app that I'm serving with Apache using mod_wsgi. I used this guide, and just switched to Apache from the Django dev server. In my 000-default.conf file I have this line
WSGIScriptAlias / /home/ubuntu/Projects/myapp/wsgi.py
Everything works fine and the homepage of my app is example.com. However, I find now that there are images (a few tilesets) that I was previously accessing at example.com/tiles which are now not accessible, because they are actually stored at /var/www/html/tiles.
I understand why the paths aren't working, but I'm wondering if there's a way I can keep running the django site from example.com while also serving the tiles from a different directory.
I think if you add a preceding configuration directive:
Alias /tiles /var/www/html/tiles
... it should fix it.
Please note that order of Apache configuration directives may matter. More information about Apache and Alias.
I'm in a university and I'm provided with a public_html folder where I can put my CGI scripts. For eg. when I put PHP scripts and visit them from my browser, it works correctly and the PHP is properly interpreted.
I wish to run Django apps in this environment and I know that the university runs an apache server and had mod_php and mod_python installed, although I think I'm not allowed to modify the httpd.conf etc.
All the tutorials that I've read about Django on mod_python ask me to modify the httpd.conf, is there any way I can get my Django site running by making non-sudo changes only?
You can try to put your directives in a .htaccess file in your directory. Dependent on the server config, it might work.
I have some django projects that I worked on and I want to deploy them with wamp server. I want that my structure would look like this:
/www
/project1
/static
/media
/templates
/project1
/settings.py
/urls.py
/app1
/app2
/project2
/static
/media
/templates
/project1
/settings.py
/urls.py
/app1
/app2
Then the urls would point to:
http://localhost/project1/(urls of project1)
http://localhost/project2/(urls of project2)
Each project uses a different database, a different admin site (some customized), and so on. I will never need to share data between them. I tried searching and reading about it, and using multiple WSGI scripts seems really buggy. Also as I understand it, I can't use the recommended daemon mode because I'm using windows.
Is it frowned upon to use multiple wsgi scripts on the same server? Should I try to create one that will handle all the projects? How would it look like, and how would the apache be configured to work with it? Is my intended structure above completely wrong?
I am using Apache 2.2e with mod_wsgi 3.3, Django 1.5.1 and python 2.7
No it is not frowned on to use multiple WSGI scripts and doing so is not buggy as such, except to the extent that Django generates a dodgy WSGI script file which you need to change to ensure you don't get environment variable leakage.
That said, you may still have issues with third party C extension modules for Python which are broken and don't work in sub interpreters, which is why it is preferred to use daemon mode if you can, as you can workaround such buggy third party modules.
So overall there is no issue with mod_wsgi, but you may encounter issues if using other software which uses a sub optimal way of configuring things, or which are broken by design.
Personally I would suggest simply not using Windows as it is a poor environment to be running Python web applications. Only use Windows if you have absolute no choice.
I am very new to apache and django, so execuse me if this question is simple. I am trying to deploy an existing site to an apache server. For the time being, the site is still in development so I am only deploying it as a virtualhost on my local machine.
I am using Django's WSGI module in the deployment. In my site's config file, I have the following aliases:
Alias /media/ /home/tester/Desktop/siteRootDir/media
Alias /content/ /home/tester/Desktop/siteRootDir/content
WSGIScriptAlias /c /home/tester/Desktop/siteRootDir/deploy/site.wsgi
When I run apache and go to localhost/c I was getting the (13)PermissionDenied error in the apache log. To get around that error, I (admitedly stupidly) ran
chmod -R 777 /home/tester/Desktop/siteRootDir
I know that is not the way to deal with the issue, but I just wanted the site to work so I can continue its development.
So my question is, what are the correct permission settings to the siteRootDir directory and its sub-directories such that the site will run and I do not expose unnecessary files in the directory.
Also, I realize that this is not an ideal set up and I will likely run into problems when I deploy the site in production. Can anyone please suggest a better organizational approach to this?
Thanks!
The tightest permissions possible would be 0600 for files and 0700 for dir's and as a owner the user owning the apache processes. This user differs per OS and flavor (e.g. for OSX it's www, for Debian/Ubuntu it's www-data).
This would probably too tight for a development server. At least would you like to be able to modify all your files through your IDE of text editor, so either you should add ACLs for yourself (i.e. the user that edits the Django files, templates and static files).
Also, in a production server you want the apache user to be able to write to directories that hold web uploaded content. That would be somewhere in your static files section (or on a different dedicated static files server).
I have apache set up on my local machine to serve some django projects. I am trying to develop another site that is not a django site. When I try to look at the non-django site, apache tries to interpret its url through django, and gives an error that the url does not match any patterns in urls.py.
I can see the non-django site by commenting out the django-specific parts of httpd.conf and restarting apache. But I know there is a way to tell apache not to try to interpret certain urls through django, or to only interpret certain urls through django.
I think the relevant parts of my setup are:
All django projects are in /srv/python-environments/env_name/django_project_name
All non-django sites are in /var/www/site_name
The non-django sites consist of static html files, a wordpress blog, and a few simple (non-django) python scripts.
I think I have set up all localhost urls to be interpreted as django urls through this line in httpd.conf, but I can't figure out how to change it:
WSGIScriptAlias / /srv/python-environments/phs_comp_env/phs_competencies/apache/django.wsgi
I am running ubuntu 10.04, apache 2.2, django through mod_wsgi.
What do I need to change, or what other information do I need to provide?
For the record, this is what worked. I placed the non-django site configuration before the django site configuration:
Alias /non-django_site/ /var/www/non-django_site/
<Directory /var/www/non-django_site>
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
You don't provide enough information about the other non Python web application. One can only guess you are talking about PHP. Read:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive
Use the AddHandler method of mapping WSGI application and especially the solution towards the end of that section of the documentation.