gpt4 book ai didi

python - 如何在 LXLE 上使用 Apache 和 mod_wsgi 为 Django 应用程序提供服务

转载 作者:太空宇宙 更新时间:2023-11-03 21:26:35 26 4
gpt4 key购买 nike

我尝试使用 mod_wsgi 从 Django 通过 Apache 2.4.18 提供网页服务,并在访问本地主机时收到错误 403 Forbidden。

系统:LXLE Unix Apache 2.4.18Django 版本 1.11.17libapache2-mod-wsgi-py3i

遵循的程序:https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

症状:

  1. 更改 000-default.conf 文件之前,默认 Apache 页面可通过 localhost 地址访问
  2. 按如下方式更改 000-default.conf 文件后,访问本地主机地址时收到错误 403-Forbidden
  3. 如果我启动 Django 服务器,则可以通过 localhost:8000 访问默认 Django 页面

配置:/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

**#FROM HERE!!!**
Alias /static /home/florian/django/myproject/myproject/static
<Directory /home/florian/django/myproject/myproject/static>
Require all granted
</Directory>

<Directory /home/florian/django/myproject/myproject/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess myproject python-path=/home/florian/django/myproject python-home=/home/florian/django/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/florian/django/myproject/myproject/myproject/wsgi.py


</VirtualHost>

Apache 错误日志:

(myprojectenv) florian@desktop:~/django/myproject/myproject$ tail -n 10 /var/log/apache2/error.log
[Sun Dec 16 09:35:25.721695 2018] [authz_core:error] [pid 10317:tid 140256502339328] [client 127.0.0.1:54346] AH01630: client denied by server configuration: /home/florian/django/myproject/myproject/myproject/wsgi.py
[Sun Dec 16 09:44:33.817490 2018] [authz_core:error] [pid 10316:tid 140256510732032] [client 127.0.0.1:54504] AH01630: client denied by server configuration: /home/florian/django/myproject/myproject/myproject/wsgi.py
[Sun Dec 16 09:45:07.820025 2018] [authz_core:error] [pid 10316:tid 140256451983104] [client 127.0.0.1:54516] AH01630: client denied by server configuration: /home/florian/django/myproject/myproject/myproject/wsgi.py
[Sun Dec 16 09:52:32.657271 2018] [mpm_event:notice] [pid 10313:tid 140256727914368] AH00494: SIGHUP received. Attempting to restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sun Dec 16 09:52:32.718483 2018] [wsgi:warn] [pid 10313:tid 140256727914368] mod_wsgi: Compiled for Python/3.5.1+.
[Sun Dec 16 09:52:32.718498 2018] [wsgi:warn] [pid 10313:tid 140256727914368] mod_wsgi: Runtime using Python/3.5.2.
[Sun Dec 16 09:52:32.720846 2018] [mpm_event:notice] [pid 10313:tid 140256727914368] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sun Dec 16 09:52:32.720930 2018] [core:notice] [pid 10313:tid 140256727914368] AH00094: Command line: '/usr/sbin/apache2'
[Sun Dec 16 09:53:50.049998 2018] [authz_core:error] [pid 10925:tid 140256630511360] [client 127.0.0.1:54568] AH01630: client denied by server configuration: /home/florian/django/myproject/myproject/myproject/wsgi.py
(myprojectenv) florian@desktop:~/django/myproject/myproject$

最佳答案

您没有在 apache 配置中指定任何 ServerName:

ServerName localhost

另请检查您是否在 settings.py 中指定了任何 allowed_host

ALLOWED_HOSTS = ["*"]

关于python - 如何在 LXLE 上使用 Apache 和 mod_wsgi 为 Django 应用程序提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53800478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com