简体   繁体   中英

Hooking Django App to subdirectory using mod_wsgi and apache on Centos 5

Background:

I am working on bringing a Django App into production for my office. So far the app has been developed and works and all that needs to be done is to deploy said app. A task that is unfortunately more cumbersome than developing the app itself. I am working on a Centos 5.11 server with Apache 2.2, mod_wsgi 3.3 and both Python 2.7 and Django 1.9 in virtualenv.

The problem

The issue I am running into is hooking the Django App to my domain's subdirectory (www.abc.example.com/FR/) but I am running into problems when configuring apache's httpd.conf where my added settings do not seem to be saved. I have run the following commands as per the httpd.conf's comments on making sure changes are saved upon restart:

/usr/local/cpanel/bin/apache_conf_distiller --update 
/usr/local/cpanel/bin/build_apache_conf

The guides that I have used have lead me to the following code: * note that '~' is representative of /home/[username]

httpd.conf

LoadModule wsgi_module extramodules/mod_wsgi.so

...

WSGIScriptAlias /FR ~/public_html/FR/django.wsgi
WSGIPythonPath ~/public_html/FR

<Directory ~/mydjango/IFTP>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

django.wsgi at ~/public_html/FR/django.wsgi

import os
import sys

sys.path.append('~/mydjango')
sys.path.append('~/mydjango/IFTP')

os.environ['DJANGO_SETTINGS_MODULE'] = 'IFTP.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

wsgi.py at ~/mydjango/IFTP/wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "IFTP.settings")

application = get_wsgi_application()

Edit 1:

My apologies, I should have further specified that the problem is that these settings are not taking effect. When I go to www.abc.example.com/FR/ I encounter a 404 not found so the wsgi script is either misconfigured or not setup properly, which is where I need assistance.

After searching around I discovered that the issues were in the django.wsgi file that provided an unnecessary extra layer. I changed my httpd.conf file to the code below, further specifying the path for my virtualenv and linking to the wsgi.py file.

LoadModule wsgi_module extramodules/mod_wsgi.so

WSGIScriptAlias /FR ~/mydjango/IFTP/wsgi.py
WSGIPythonPath "~/mydjango/lib/python2.7/site-packages:~/mydjango"
WSGIPythonHome ~/mydjango

<Directory ~/mydjango/IFTP>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM