apache 部署django遇到问题

发布于 2022-09-05 09:21:00 字数 7083 浏览 40 评论 0

运行环境:操作系统centos7,mysql5.7,redis,httpd(apache),mod_wsgi(python3),conda环境

访问路径遇到这种情况:

clipboard.png

这种错误是怎么回事?

httpd.conf如下:


ServerRoot "/usr/local/apache2"


Listen 80

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so

<IfModule unixd_module>
User daemon
Group daemon

</IfModule>


ServerAdmin you@example.com


<Directory />
    AllowOverride none
    Require all denied
</Directory>


DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

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

ErrorLog "logs/error_log"

LogLevel warn

<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 "logs/access_log" common

</IfModule>

<IfModule alias_module>


    ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"

</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

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

<IfModule mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz



</IfModule>

<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>

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

Listen 5090
ServerName localhost:80
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf

httpd-vhosts.conf如下:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "logs/dummy-host.example.com-error_log"
#    CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>

#<VirtualHost *:80>
#   ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/usr/local/apache2/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>

<VirtualHost *:5090>
    ServerName dpsapp
    ServerAdmin YTkks001@163.com
    ServerAlias dpsapp
    
    WSGIDaemonProcess dpsplat python-path=/home/miniconda3/envs/keshihua/lib/python3.6/site-packages
    WSGIProcessGroup dpsplat
    WSGIScriptAlias / /home/dpsplat/visualplat/wsgi.py


    DocumentRoot "/home/dpsplat/visualplat"
    <Directory /home/dpsplat/visualplat>
        Require all granted
    </Directory>

    ErrorLog /usr/local/apache2/logs/error-dpsplat.log
    CustomLog /usr/local/apache2/logs/access-dpsplat.log combined

</VirtualHost>

django 目录如下:

clipboard.png

error的log如下:

[Wed Aug 09 02:15:55.153831 2017] [wsgi:error] [pid 93492:tid 140605879445248] [client 192.168.157.133:26905] Timeout when reading response headers from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py
[Wed Aug 09 02:21:30.172963 2017] [wsgi:error] [pid 93492:tid 140605871052544] [client 192.168.157.133:26913] Timeout when reading response headers from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py

#时间戳去掉
Timeout when reading response headers from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py
Timeout when reading response headers from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py
Truncated or oversized response headers received from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py
Timeout when reading response headers from daemon process 'dpsplat': /home/dpsplat/visualplat/wsgi.py

django的wsgi.py如下:

"""
WSGI config for visualplat project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os
from os.path import dirname, abspath

from django.core.wsgi import get_wsgi_application

import sys

PROJECT_DIR = dirname(dirname(abspath(__file__)))
sys.path.insert(0,PROJECT_DIR)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "visualplat.settings")

application = get_wsgi_application()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那些过往 2022-09-12 09:21:00

先把所有apache和uwsgi都关闭,开始排查问题

1、先排除django的环境问题, 看看程序有没有什么包没装

python manage.py runserver 0.0.0.0:5090

2、如果顺利运行,则访问http://ip:5090看看是否能正常访问

3、如不能正常访问检查一下防火墙是开着还是关了,如果是开着看看端口是否已加入

以上问题都通过,再去开uwsgi及ahache的配置问题

成熟稳重的好男人 2022-09-12 09:21:00

这种情况我也遇到过,是python的问题,不是apache的问题。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文