Use mod_wsgi daemon mode and run the Django application. Set the user / group for this daemon process group as the special special user of the Django application, which is different from the Apache user. Use the WSGI script file that you are using outside the scope of the Django project.
The directory containing the WSGI script file can then be 700 if it belongs to an Apache user. The WSGI script file inside it should only be 400 and should not even belong to the Apache user, but may belong to the root user or to a separate user of the Django application. All Apache users will need the ability to see the WSGI script file in the directory; they will not need to open the WSGI script file.
All your project code and virtual environment can be in a directory structure owned by an individual Django user, while all directories are 0700 and files that can be read / written as needed or as needed. Only a user accessible Django application should have access, since all calls will be made from the daemon process group running as that user.
This way you have limited access so that the Apache user cannot even see your project code. Thus, if hosting other things in the same Apache, such as PHP, there is no risk that a break in the PHP code can access the files.
source share