简体   繁体   English

使用mod_wsgi(Apache2)设置Django

[英]Setting up Django with mod_wsgi (Apache2)

ServerName test.test.nz

    ServerAdmin webmaster@localhost
    DocumentRoot /home/aut/sampleapp


    WSGIScriptAlias /home/aut/sampleapp /home/aut/sampleapp/sampleapp/wsgi.py
    WSGIPythonPath /home/aut/sampleapp:/home/aut/sampleapp/env/lib/python2.7/site-packages

    <Directory /home/aut/sampleapp>
            AllowOverride None
            Options +FollowSymLinks
            Order allow,deny
            Allow from all
            Require all granted
    </Directory>

    <Directory /home/aut/sampleapp/sampleapp>
    <Files wsgi.py>
            Require all granted
    </Files>
    </Directory>

The above is the configuration for virtual host port 80. After restarting Apache, I got no errors, but when I go to test.test.nz, I get: 上面是虚拟主机端口80的配置。重新启动Apache之后,我没有遇到任何错误,但是当我进入test.test.nz时,我得到了:

The requested URL / was not found on this server. 在此服务器上找不到请求的URL /。

"/home/aut/sampleapp/" is where manage.py is, within that directory, there is another folder called "sampleapp" which contains the urls.py, wsgi.py etc.. “ / home / aut / sampleapp /”是manage.py所在的目录,在该目录中还有一个名为“ sampleapp”的文件夹,其中包含urls.py,wsgi.py等。

The urls.py has been edited to set the app as the index page: urls.py已被编辑为将应用程序设置为索引页面:

from django.conf.urls import url
from django.contrib import admin
from django.contrib.sitemaps import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^admin/', admin.site.urls),
]

What seems to be the problem? 似乎是什么问题?

Any help or direction would be appreciated. 任何帮助或指示,将不胜感激。

Thanks in advance, 提前致谢,

You haven't defined anything for the root path, /. 您尚未为根路径/定义任何内容。 Your wsgiscriptalias is set to "/home/aut/sampleapp" so only applies to paths under that. 您的wsgiscriptalias设置为“ / home / aut / sampleapp”,因此仅适用于该目录下的路径。

I'm not quite sure why you've done this; 我不太确定为什么要这么做。 if you want wsgi to serve your site at the root, as you usually would, you should put / there. 如果您希望wsgi像往常一样在根目录中为您的网站提供服务,则应在其中放置/

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

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