Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带有apache2配置的django wsgi提供找不到的页面404_Python_Django_Apache_Apache2 - Fatal编程技术网

Python 带有apache2配置的django wsgi提供找不到的页面404

Python 带有apache2配置的django wsgi提供找不到的页面404,python,django,apache,apache2,Python,Django,Apache,Apache2,这里的假设 testsite.com这是我的php应用程序和 testsite.com/project是python django应用程序 我的apache站点配置文件/etc/apache2/sites available/site.conf <VirtualHost *:443> ServerAdmin webmaster@testsite.com ServerName testsite.com

这里的假设

testsite.com
这是我的php应用程序和

testsite.com/project
是python django应用程序

我的apache站点配置文件
/etc/apache2/sites available/site.conf

<VirtualHost *:443>
                ServerAdmin webmaster@testsite.com
                ServerName testsite.com
                DocumentRoot /var/www/html

                WSGIDaemonProcess test python-path=/var/www/html/projectenv/test-project python-home=/var/www/html/projectenv
                WSGIProcessGroup test
                WSGIScriptAlias /project /var/www/html/projectenv/test-project/test-project/wsgi.py


                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
这是我的项目url结构

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('projectapp.urls'))
]
projectapp/url.py

from django.urls import path
from . import views

urlpatterns = [
    path('project/', views.home, name='project'),
]
设置.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_filters',
    'projectapp',

]
请建议解决方案,当我点击此url
testsite.com/project
时,它应该通过我定义的django应用程序,并呈现链接到此视图的页面。据观察,wsgi无法通过django项目结构,因此它无法识别应用程序中给出的url。或者可能是找不到应用程序结构


为了让这一切顺利进行,我应该做些什么改变,请建议我最终找到了解决方案,这是一个概念性的问题

由于上面提到的
WSGIScriptAlias
/project
,这意味着对于wsgi来说,项目范围将仅限于
/project
目录,wsgi将无法访问
/project
目录之外的其他应用程序

这就是为什么它给出了
找不到页面(404)

因此,这就是它所期望的如下内容

WSGIScriptAlias /test-project /var/www/html/projectenv/test-project/test-project/wsgi.py
因此,现在wsgi可以访问
/test project
中的所有应用程序URL

现在,我可以通过
testsite.com/testproject/project
访问django项目的url,同时访问我的php应用程序
testsite.com
,这两个应用程序都运行得非常好


这里的教训是,wsgi总是需要主项目目录路径来遍历其中的所有应用程序,尽管django官方文档中提到了它,但我们通常忽略了这个概念。希望这个答案能帮助你解决同样的问题

如果使用
testsite.com/project
它将在
testsite.com
目录中查找
project
,该目录不会作为不同的项目一起存在。最好将
project
用作子域。例如,
project.testsite.com
@Anthony:testsite.com不是目录。是我的网站域,因此每当这个url点击时,它都会通过virtualhost中提到的文档根,我建议您仔细查看
site.conf
文件中我的项目结构,我想使用url
/project
来呈现我的django应用程序。因此,请提出相应的建议
WSGIScriptAlias /test-project /var/www/html/projectenv/test-project/test-project/wsgi.py