当前位置: 首页 > 知识库问答 >
问题:

如何在LXLE上使用Apache和mod_wsgi服务Django应用程序

赵永新
2023-03-14

我正在尝试使用 Django 通过 Apache 2.4.18 提供网页mod_wsgi并在访问本地主机时收到错误 403 禁止。

系统:LXLE Unix Apache 2.4.18 Django版本1.11.17 libapache2-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 页面
  2. 更改 000-default.conf 文件如下后,我在访问本地主机地址时收到错误 403-禁止
  3. 如果我启动 Django 服务器,默认的 Django 页面可以在 localhost:8000 访问

配置:/etc/Apache 2/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>

错误日志阿帕奇:

(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$ 

共有1个答案

毋宪
2023-03-14

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

ServerName localhost

还要检查您是否在< code>settings.py中指定了任何< code>allowed_host。

ALLOWED_HOSTS = ["*"]
 类似资料:
  • 我想在Apache服务器上部署我的Flask应用程序。我在服务器上有一个帐户,并被告知“服务器可用于运行用Python编写的脚本和Web应用程序(使用django和mod_wsgi)”。 我在Windows上,要传输文件,我必须使用FTP客户端,所以我使用WinSCP。 安装mod_wsgi并不像我预期的那样简单,我无法在线获得任何清晰的文档。 因为服务器已经可以使用mod_wsgi运行Pytho

  • 我想在同一个主机上部署两个不同的django应用程序:第一个对应于url/site1,第二个对应于url/site2。这是我的配置: 这是两个应用程序的wsgi.py文件 现在,我的问题来了。当我转到服务器时,假设http://app1.sites.gr/site1它有时加载site1,有时加载site2!!!!我访问时也是如此http://app1.sites.gr/site2 ... 有时我会

  • 问题内容: 我想在同一主机中部署两个不同的django应用程序:第一个将对应于URL / site1,第二个将对应于URL / site2。这是我的配置: 这也是这两个应用程序的wsgi.py文件 现在,这是我的问题。当我转到服务器时,假设http://app1.sites.gr/site1有时加载了site1,而有时加载了site2!访问http://app1.sites.gr/site2时也是

  • 我试图在apache服务器上部署Hello world应用程序。 <代码>(http://localhost/wsgi.py)但它不起作用。 请告诉我如何配置apache conf文件以运行wsgi enable应用程序。 我的apache... 我已经使用pip命令下载了mod wsgi和django作为python模块,现在我面临着如何在apache模块目录中加载wsgi模块的问题* 我在这些

  • 问题内容: 我已经安装了Apache服务器,并且正在通过mod_wsgi处理Flask响应。我已经通过别名注册了WSGI脚本: [httpd.conf] 我在上面的路径中添加了相应的WSGI文件: [/mnt/www/wsgi-scripts/service.wsgi] 我有一个简单的Flask Python测试脚本,提供了服务模块: [/mnt/www/wsgi-scripts/service.

  • 我有一个专用的服务器上,我目前正在运行4个PHP网站。服务器配置为Apache+Nginx。每当我托管php网站时,我将文件放在public_html文件夹中,它就会开始运行。但现在我想安装nodejs应用程序。我只是对如何处理server.js文件感到困惑?又如何让它继续运行?我应该使用pm2还是永远保持它在我的ubuntu主机上永远运行。如何运行域名为example.com的网站