mod user_dir and wsgi - python

I am trying to setup a public_html/django_app folder, where all urls like ~/{username}/django would execute the .wsgi file located there.
The idea is to checkout our project inside of the django folder, and have it work for everyone without further apache config.
Right now, our project is running in /var/www/project_name, but I would like every user to be able to checkout the project in their own folder /home/{username}/public_html/django_app, and I don't want them to edit any apache config.
So I guess the question is, what is the best way / location to do this in the apache configuration. I would like to avoid creating VirtualHosts for everyone, just to change
WSGIScriptAlias django_app/ /home/{username}/django_app/core.wsgi
Thanks.

Answer:
WSGIScriptAliasMatch
^/~([^/]+)/django_app
/home/$1/public_html/django_app/core.wsgi

Related

Where to put django files on server?

I have a question. I work with one guy who is developing in Php, I am developing in Django right know. This is my first time doing something for other people and he firstly asked me to put my application to Apache Web server document root(I think he didn't know that much about Django, and he did everything this way), so I did it, because I didn't know that much about Apache and servers. But right know I am scared because I have all the python files in document root and I realized that this Web server document root \www\myproject might be accessible to other people. How should I change it, where should I put it, what is the best practice? I am deploying with mod_wsgi and Apache 2.4. In the documentation it says, that I shouldn't put code in Web server document root too, but if I put it somewhere else can I access it the same way, like I used to when it was on the Web server document root? Will I have to do something other than changing paths in Apache config?
You should put the Django project anywhere on the machine except for the apache document root, for security reasons as you have pointed out.
You can then configure apache to pint to the location of your wsgi.py which can live in the Django project if you wish:
WSGIScriptAlias / <path to the wsgi.py>
I'm not aware of a standard place to put the Django project root directory, I guess it depends on the OS and the distribution.

Django hosted on Apache - Uploading a file going to wrong location

I have a simple website that allows the user to upload a file to my server. I want the file to be uploaded into my django project folder in a sub directory.
Everything is working fine but when I use the upload feature on my website I get a permissions denied on the folder /var/www BUT the thing is I changed the DocumentRoot to equal /mnt/public/apps - which is where I want my uploaded files to go (the upload creates a sub directory).
I have correct permissions in /mnt/public but I can't figure out how to point django or apache so that my upload goes to the /mnt/public/apps root instead of /var/www
Any help would be greatly appreciated!
As Alasdair said in the comments, which was a super quick reply (thanks!), the correct fix for my problem was to add the MEDIA_ROOT variable to my settings.py file.

Django deployed app/project can't write to a file

I am working on a Django based application whose location on my disk is home/user/Documents/project/application. Now this application takes in some values from the user and writes them into a file located in a folder which is under the project directory i.e home/user/Documents/project/folder/file. While running the development server using the command python manage.py runserver everything worked fine, however after deployment the application/views.py which accesses the file via open('folder/path','w') is not able to access it anymore, because by default it looks in var/www folder when deployed via apache2 server using mod_wsgi.
Now, I am not putting the folder into /var/www because it is not a good practise to put any python code there as it might become readable clients which is a major security threat. Please let me know, how can I point the deployed application to read and write to correct file.
The real solution is to install your data files in /srv/data/myapp or some such so that you can give the webserver user correct permissions to only those directories. Whether you choose to put your code in /var/www or not, is a separate question, but I would suggest putting at least your wsgi file there (and, of course, specifying your <DocumentRoot..> correctly.

Changing documentroot in openshift

We're developing an android app with an api backend that we want to deploy via openshift.
The problem is we have the android app and the webservice in the same github project in two different folders. So I need to change the document_root so that openshift can find the python wsgi.py file.
I've already tried this:
rhc env-set OPENSHIFT_PYTHON_WSGI_APPLICATION="\${OPENSHIFT_REPO_DIR}/server/wsgi.py" --app api
But then it wouldn't find the requirements.txt because it still uses the wrong document_root.
I tried putting the requirements.txt in the root dir, that way it parses the file but installs the lib's in the wrong place.
I've also tried
rhc env-set OPENSHIFT_DOCUMENT_ROOT="\${OPENSHIFT_REPO_DIR}/server" --app api
But that didn't work either
Help please!!!!
As of the March release of OpenShift online, you can now specify the path to your WSGI with the 'OPENSHIFT_PYTHON_WSGI_APPLICATION' environment variable. You can read more about it here: https://www.openshift.com/blogs/openshift-online-march-2014-release-blog
Are you looking for OPENSHIFT_PYTHON_REQUIREMENTS_PATH
https://developers.openshift.com/en/python-overview.html

Apache2 and .psp files

I have a server setup, and working. Trying to get add python scripting support. I seem to have it working, but how do I configure Apache2 to look for index.psp with out me needing to be specific. Meaning, I can specify index.psp, and it works, but I want apache to search for index.html, then index.php, and then also look for index.psp. How do I include .psp in the search?
Set DirectoryIndex index.html index.psp index.psp (docs).

Categories

Resources