how can run django on centos using wsgi

流过昼夜 提交于 2019-12-11 17:47:30

问题


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 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

but when I browse my site I get error 500 : Internal Server Error

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 "

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.


回答1:


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

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

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

This is instead of using mod_wsgi-express setup-server.

You can then use:

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

as root.

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

so that any static files are copied to the STATIC_ROOT directory you specified in the Django settings.py file.

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.



来源:https://stackoverflow.com/questions/24760872/how-can-run-django-on-centos-using-wsgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!