运行 Apache 与 mod_wsgi 和 django

Run Apache with mod_wsgi and django

无法使用 Apache + Django 启动服务器

OS:麦克OS卡特琳娜
阿帕奇:2.4.43
Python: 3.8
姜戈:3.0.7

由 Brew 的 Apache 使用。
mod_wsgi 通过 pip 安装。

应用程序是通过标准命令创建的

django-admin startproject project_temp

调用命令时应用程序启动

python manage.py runserver

开始 mod_wsgi - 一切正常

mod_wsgi-express start-server

当我启动 Apache 时,无法访问服务器。 在“本地主机:80”检查。

告诉我,启动服务器需要做什么?

HTTP 设置:

ServerRoot "/usr/local/opt/httpd"
ServerName localhost
Listen 80

LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so
LoadModule authn_file_module lib/httpd/modules/mod_authn_file.so
LoadModule authn_core_module lib/httpd/modules/mod_authn_core.so
LoadModule authz_host_module lib/httpd/modules/mod_authz_host.so
LoadModule authz_groupfile_module lib/httpd/modules/mod_authz_groupfile.so
LoadModule authz_user_module lib/httpd/modules/mod_authz_user.so
LoadModule authz_core_module lib/httpd/modules/mod_authz_core.so
LoadModule access_compat_module lib/httpd/modules/mod_access_compat.so
LoadModule auth_basic_module lib/httpd/modules/mod_auth_basic.so
LoadModule reqtimeout_module lib/httpd/modules/mod_reqtimeout.so
LoadModule filter_module lib/httpd/modules/mod_filter.so
LoadModule mime_module lib/httpd/modules/mod_mime.so
LoadModule log_config_module lib/httpd/modules/mod_log_config.so
LoadModule env_module lib/httpd/modules/mod_env.so
LoadModule headers_module lib/httpd/modules/mod_headers.so
LoadModule setenvif_module lib/httpd/modules/mod_setenvif.so
LoadModule version_module lib/httpd/modules/mod_version.so
LoadModule unixd_module lib/httpd/modules/mod_unixd.so
LoadModule status_module lib/httpd/modules/mod_status.so
LoadModule autoindex_module lib/httpd/modules/mod_autoindex.so
LoadModule alias_module lib/httpd/modules/mod_alias.so
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
LoadModule wsgi_module /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-darwin.so

<Directory />
    AllowOverride All
</Directory>

<Files ".ht*">
    Require all denied
</Files>

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "/usr/local/var/log/httpd/access_log" common
</IfModule>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    TypesConfig /usr/local/etc/httpd/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule proxy_html_module>
    Include /usr/local/etc/httpd/extra/proxy-html.conf
</IfModule>

<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
</IfModule>

WSGIScriptAlias / /Users/r/Projects/project_temp/project_temp/wsgi.py
WSGIPythonHome /Library/Frameworks/Python.framework/Versions/3.8

<VirtualHost localhost:80>
    LogLevel warn
    ErrorLog /Users/r/Projects/project_temp/log/error.log
    CustomLog /Users/r/Projects/project_temp/log/access.log combined

    <Directory /Users/r/Projects/project_temp/project_temp>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

我不太了解你的配置,但我的 Linux / Apache / WSGI 配置中确实有这一行:

WSGIDaemonProcess constr processes=2 threads=15 display-name=%{GROUP} python-home=/www/constr/venv python-path=/www/constr
WSGIProcessGroup constr

问题的解决

  1. 查看了统计信息,谁在监听端口 - 没有找到 httpd
  2. 运行 httpd 使用 brew。使用 apachectl 启动 - 它有效

django 还有其他问题,但那是另一个问题