简体   繁体   English

在Centos 5上使用mod_wsgi和apache将Django App挂接到子目录

[英]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. 我正在为我的办公室将Django应用程序投入生产。 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. 我正在使用Apache 2.2,mod_wsgi 3.3以及virtualenv中的Python 2.7和Django 1.9在Centos 5.11服务器上工作。

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. 我遇到的问题是将Django应用挂接到我域的子目录(www.abc.example.com/FR/),但是在配置apache的httpd.conf时却遇到了问题,其中似乎未保存我添加的设置。 I have run the following commands as per the httpd.conf's comments on making sure changes are saved upon restart: 我已经按照httpd.conf的注释运行了以下命令,以确保在重新启动后保存更改:

/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] 我使用的指南将我引导至以下代码:*请注意,“〜”代表/ home / [用户名]

httpd.conf 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 django.wsgi,位于〜/ 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 wsgi.py,位于〜/ 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: 编辑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. 当我转到www.abc.example.com/FR/时,遇到找不到404的消息,因此wsgi脚本配置错误或设置不正确,这是我需要帮助的地方。

After searching around I discovered that the issues were in the django.wsgi file that provided an unnecessary extra layer. 搜索后,我发现问题出在django.wsgi文件中,该文件提供了不必要的额外层。 I changed my httpd.conf file to the code below, further specifying the path for my virtualenv and linking to the wsgi.py file. 我将httpd.conf文件更改为以下代码,进一步指定了virtualenv的路径并链接到wsgi.py文件。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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