简体   繁体   English

用apache2部署django项目时出现404错误

[英]404 error when deploying django project with apache2

I tried to create a new django project on apache2, but I got 404 error.我试图在 apache2 上创建一个新的 django 项目,但出现 404 错误。 Here are what I did.这是我所做的。

-In /home/ubuntu/django directory, type - 在 /home/ubuntu/django 目录中,键入

django-admin startproject proj

-Edit proj/proj/wsgi.py as follows. - 编辑proj/proj/wsgi.py 如下。

import os
import sys


from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

sys.path.append('/home/ubuntu/django/proj');
sys.path.append('/home/ubuntu/django/proj/proj');

application = get_wsgi_application()

-Edit ALLOWED_HOSTS in proj/proj/settings.py as follows. - 编辑proj/proj/settings.py中的ALLOWED_HOSTS如下。

ALLOWED_HOSTS = ['example.com']

-Edit /etc/apache2/conf-available/wsgi.conf as follows. - 编辑 /etc/apache2/conf-available/wsgi.conf 如下。

WSGIScriptAlias /proj /home/ubuntu/django/proj/proj/wsgi.py
WSGIPythonPath /home/ubuntu/django/proj

<Directory /home/ubuntu>
   Require all granted
</Directory>

<Directory /home/ubuntu/proj/proj>
 <Files wsgi.py>
  Require all granted
 </Files>
</Directory>

-Restart apache2 as -重启apache2为

/etc/init.d/apache2 restart

-Access to http://example.com/proj , and then got 404 error as follows. - 访问http://example.com/proj ,然后得到404错误如下。

Page not found (404)
Request Method: GET
Request URL:    http://example.com/proj/
Using the URLconf defined in proj.urls, Django tried these URL patterns, in this order:

admin/
The empty path didn't match any of these.

My enviroment is as follows.我的环境如下。

  • Ubuntu 18.04 LTS (AWS) Ubuntu 18.04 LTS (AWS)
  • Apache/2.4.29阿帕奇/2.4.29
  • Python 3.6.9 Python 3.6.9
  • Django 3.0.5 Django 3.0.5

How can I solve this 404 error?我该如何解决这个 404 错误?

Do you have '/admin' in your urls.py file?你的 urls.py 文件中有 '/admin' 吗? You may also need to change the apache2 settings from /home/ubuntu/proj/proj to /home/ubuntu/django/proj/proj您可能还需要将 apache2 设置从 /home/ubuntu/proj/proj 更改为 /home/ubuntu/django/proj/proj

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

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