使用mod_wsgi和Django运行Apache

2024-05-20 12:32:04 发布

您现在位置:Python中文网/ 问答频道 /正文

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

OS:MacOS Catalina
Apache:2.4.43
Python:3.8
Django:3.0.7

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

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

django-admin startproject project_temp

调用命令时,应用程序启动

python manage.py runserver

在mod_wsgi的开始阶段-一切正常

mod_wsgi-express start-server

当我启动Apache时,服务器无法访问。 选中“localhost:80”

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

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>

Tags: projectlogmodulesmodwsgisolibusr
2条回答

我对您的配置不太了解,但在我的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. 使用brew运行httpd。使用apachectl启动-它起作用了

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

相关问题 更多 >