使用mod_wsgi在apache上运行django webapp

时间:2022-09-17 07:52:57

I am new to working with apache and mod_wsgi. But I do have little experience in django, so from some tutorials I tried to run django app through apache webserver using mod_wsgi.
I created mysite in /var/www/
then in mysite/application I created application.wsgi ...

我是新手使用apache和mod_wsgi。但我确实没有django的经验,所以从一些教程中我尝试使用mod_wsgi通过apache webserver运行django app。我在/ var / www /中创建了mysite然后在mysite / application中我创建了application.wsgi ...

import os
import sys

sys.path.append('/var/www/mysite/application')

os.environ['PYTHON_EGG_CACHE'] = '/var/www/mysite/.python-egg'

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

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

and in /etc/httpd/sites-available I created file named mysite.conf ...

并在/ etc / httpd / sites-available中我创建了名为mysite.conf的文件...

<VirtualHost *:80>
   ServerName mysite.com
   ServerAdmin id@somewhere.com
   ServerAlias mysite.com
   DocumentRoot /var/www/mysite/   
<Directory /var/www/mysite>
Options FollowSymLinks
AllowOverride None
  Order allow,deny
  Allow from all
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Directory>
WSGIDaemonProcess mysite processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup mysite
</Virtualhost>

Then I ran a2ensite mysite.conf, didn't showed any error.
Then in /etc/httpd/hosts/ I added one line my-ipddress mysite.com
I gave permission chmod 777 to all the above files and to folder /var/www/mysite. Now when I open mysite.com on browser I see apahce's default page nothing from django.
I am using fedora 21.

然后我运行a2ensite mysite.conf,没有显示任何错误。然后在/ etc / httpd / hosts /我添加了一行my-ipddress mysite.com我将chmod 777的权限授予所有上述文件和文件夹/ var / www / mysite。现在,当我在浏览器上打开mysite.com时,我发现apahce的默认页面没有django。我正在使用fedora 21。

1 个解决方案

#1


1  

You haven't put in anything in that configuration to serve your Django site via WSGI: you're missing the WSGIScriptAlias line (see the documentation:

您没有在该配置中添加任何内容以通过WSGI为您的Django站点提供服务:您缺少WSGIScriptAlias行(请参阅文档:

WSGIScriptAlias /  /var/www/mysite/mysite/wsgi.py

Note that you shouldn't really be putting things in /var/www; and also you shouldn't need to create your own WSGI file, Django creates one for you when you create a project.

请注意,你不应该把东西放在/ var / www;而且您也不需要创建自己的WSGI文件,Django在您创建项目时为您创建一个。

#1


1  

You haven't put in anything in that configuration to serve your Django site via WSGI: you're missing the WSGIScriptAlias line (see the documentation:

您没有在该配置中添加任何内容以通过WSGI为您的Django站点提供服务:您缺少WSGIScriptAlias行(请参阅文档:

WSGIScriptAlias /  /var/www/mysite/mysite/wsgi.py

Note that you shouldn't really be putting things in /var/www; and also you shouldn't need to create your own WSGI file, Django creates one for you when you create a project.

请注意,你不应该把东西放在/ var / www;而且您也不需要创建自己的WSGI文件,Django在您创建项目时为您创建一个。