如何可以运行在使用WSGI Django的CentOS的

问题描述:

我试着2的方式来配置WSGI使用Django我的网站。
我的根项目文件在/ var /运行/对myApp。
这是我的wsgi.py:

I try 2 way to config wsgi to use Django for my site. my root project file is in /var/run/myApp. this is my wsgi.py :

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

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

1.I安装需要在Apache和使用的CentOS作为操作系统上运行Django的一切。我使用网站运行wsgi.I使用此命令设置我的服务器:

1.I install everything that need to run Django on apache and using centos as OS. I use this site to run wsgi.I use this command to setup my server :

mod_wsgi-express setup-server wsgi.py --port=80 --user test --group test --server-root=/var/run/myApp/mod_wsgi-express-80

在那之后我运行此命令,一切都很好:

after that I run this command and everything is fine:

/var/run/myApp/mod_wsgi-express-80/apachectl start

但是当我浏览我的网站,我得到错误 500:内部服务器错误

2.我也已经尝试另一种方式来配置的Apache的conf文件,但我的Apache的error_log得到这个错误:

2.I also already try another way to config apache conf file but I get this error in error_log of apache :

" Target WSGI script not found or unable to stat: /run "

这是我在httpd.conf中写的:

and this is what I write in httpd.conf:

WSGIDaemonProcess mySite user=test group=test
WSGIProcessGroup mySite

<VirtualHost *:80>
    WSGIScriptAlias / run/myApp/my_App/wsgi.py
    <Directory run/myApp/my_App>
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

是什么问题呢?谢谢。

what is problem? thanks.

如果使用Django,你最好使用的Django的mod_wsgi的前preSS集成。

If using Django, you are better off using the mod_wsgi express integration for Django.

因此​​,添加'mod_wsgi.server INSTALLED_APPS 在Django settings.py

Thus, add 'mod_wsgi.server' to INSTALLED_APPS in Django settings.py.

然后使用 - 设置 - 仅选项到 runmodwsgi 管理​​命令:

Then use --setup-only option to the runmodwsgi management command:

python manage.py runmodwsgi --setup-only --port=80 --user test --group test --server-root=/var/run/myApp/mod_wsgi-express-80

这是不是使用 mod_wsgi的-EX preSS设置服务器

您可以再使用:

/var/run/myApp/mod_wsgi-express-80/apachectl start

为根。

通过使用 runmodwsgi 管理​​命令,mod_wsgi的前preSS将在Django的静态文件目录因素并将其添加到自动生成的Apache配置。

By using the runmodwsgi management command, mod_wsgi express will factor in the Django static files directory and add it to the generated Apache configuration automatically.

在使用静态文件,只记得运行:

In using static files, just remember to run:

python manage.py collectstatic

,以便任何静态文件复制到你的Django的 settings.py 文件中指定的 STATIC_ROOT 目录。

在使用管理命令,mod_wsgi的前preSS也应该正确地安装顶级目录的Django作为主目录应用程序,并确保模块搜索路径,使您的项目模块中找到适当的设置。

In using the management command, mod_wsgi express should also correctly setup the top level directory for Django as the home directory for the application and ensure the module search path is set appropriately so that your project modules are found.