Installing Django with mod_wsgi

笑着哭i 提交于 2019-12-19 09:04:19

问题


I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is WAMP2.0. I've been a PHP programmer for years now and I've been using WAMPServer since long ago. I installed the mod_wsgi.so and seems to work just fine (no services error) but I can't configure the httpd.conf to look at my python scripts located outside the server root.

For now, I'm cool with overriding the document root and serve the django app from the document root instead so the httpd.conf line should look like this:

    WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi

but the server's response is a 403 Forbidden


回答1:


You have:

WSGIScriptAlias / /C:/Users/Marcos/Documents/mysite/apache/django.wsgi

That is wrong as RHS is not a valid Windows pathname. Use:

WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi

That is, no leading slash before the Windows drive specifier.

Other than that, follow the mod_wsgi documentation others have pointed out.


Poster edited question to change what now would appear to be a typo in the post and not a problem with his configuration.

If that is the case, next causes for a 403 are as follows.

First is that you need to also have:

<Directory C:/Users/Marcos/Documents/mysite/apache>
Order deny,allow
Allow from all
</Directory>

If you don't have that then Apache isn't being granted rights to serve a script from that directory and so will return FORBIDDEN (403).

Second is that you do have that, but don't acknowledge that you do, and that that directory or the WSGI script file is not readable by the user that the Apache service runs as under Windows.




回答2:


Have you seen http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango ?

You need more than one line to assure that Apache will play nicely.

Alias /media/ /usr/local/django/mysite/media/

<Directory /usr/local/django/mysite/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi

<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>

The <Directory>, as well as appropriate file system ownership and permissions are essential.

The usr/local/django/mysite/apache directory has your Python/Django app and the all-important django.wsgi file. You must provide permissions on this directory.




回答3:


mod_wsgi's documentation is very good. Try using their quick configuration guide and go from there: http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide



来源:https://stackoverflow.com/questions/1195260/installing-django-with-mod-wsgi

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