简体   繁体   English

使用 mod_wsgi 和 django 运行 Apache

[英]Run Apache with mod_wsgi and django

Can't start server using Apache + Django无法使用 Apache + Django 启动服务器

OS: MacOS Catalina操作系统:MacOS Catalina
Apache: 2.4.43 Apache:2.4.43
Python: 3.8 Python:3.8
Django: 3.0.7 Django:3.0.7

Used by Apache from Brew.由 Brew 的 Apache 使用。
mod_wsgi installed via pip. mod_wsgi 通过 pip 安装。

The application is created through the standard command应用程序是通过标准命令创建的

django-admin startproject project_temp

The application starts when the command is called调用命令时应用程序启动

python manage.py runserver

At start for mod_wsgi - everything is OK在 mod_wsgi 开始时 - 一切正常

mod_wsgi-express start-server

When I start Apache, the server is not accessible.当我启动 Apache 时,服务器无法访问。 Checked at "localhost: 80".在“本地主机:80”检查。

Tell me, what do I need to do to start the server?告诉我,我需要做什么才能启动服务器?

Httpd settings: Httpd设置:

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>

I don't know much about your configuration, but I do have this line in my Linux / Apache / WSGI configuration:我不太了解您的配置,但我的 Linux / Apache / WSGI 配置中确实有这一行:

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

Solution to the problem问题的解决方案

  1. looked at statistics, who listens to ports - did not find httpd看了统计,谁在监听端口——没找到 httpd
  2. ran httpd using brew.使用 brew 运行 httpd。 Launched using apachectl - it worked使用 apachectl 启动 - 它有效

There were other problems with django, but that's another question django 还有其他问题,但这是另一个问题

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

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