Apache 无法为我的 Python 应用程序提供服务

Apache 无法为我的 Python 应用程序提供服务

这是我的 Apache 配置:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName 31.220.49.197
        WSGIDaemonProcess ts threads=25
        WSGIProcessGroup ts
        Alias /static /home/email-validator/static
        WSGIScriptAlias / /home/email-validator/index.wsgi

        # Set access permission
        <Directory />
                Allow from all
                Require all granted
        </Directory>

</VirtualHost>

这是我的index.wsgi:

import os
import sys
import site

# Add the app's directory to the PYTHONPATH
sys.path.append('/home/email-validator')
sys.path.append('/home/email-validator/email_validator')

os.environ['DJANGO_SETTINGS_MODULE'] = 'email_validator.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

编辑:apache error.log

[Sat Nov 15 12:28:09.374301 2014] [mpm_event:notice] [pid 3827:tid 3074431616] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Sat Nov 15 12:28:09.374426 2014] [core:notice] [pid 3827:tid 3074431616] AH00094: Command line: '/usr/sbin/apache2'
[Sat Nov 15 12:32:45.009711 2014] [mpm_event:notice] [pid 3827:tid 3074431616] AH00491: caught SIGTERM, shutting down
[Sat Nov 15 12:32:46.137115 2014] [so:warn] [pid 4297:tid 3074935424] AH01574: module wsgi_module is already loaded, skipping
[Sat Nov 15 12:32:46.142088 2014] [mpm_event:notice] [pid 4298:tid 3074935424] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Sat Nov 15 12:32:46.142125 2014] [core:notice] [pid 4298:tid 3074935424] AH00094: Command line: '/usr/sbin/apache2'
[Sat Nov 15 12:42:04.023659 2014] [mpm_event:notice] [pid 4298:tid 3074935424] AH00491: caught SIGTERM, shutting down
[Sat Nov 15 12:42:04.248193 2014] [so:warn] [pid 4409:tid 3074857600] AH01574: module wsgi_module is already loaded, skipping
[Sat Nov 15 12:42:04.252825 2014] [mpm_event:notice] [pid 4410:tid 3074857600] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Sat Nov 15 12:42:04.252860 2014] [core:notice] [pid 4410:tid 3074857600] AH00094: Command line: '/usr/sbin/apache2'

是否配置

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:127.0.0.2  P-t-P:127.0.0.2  Bcast:0.0.0.0  Mask:255.255.255.255
          inet6 addr: 2a02:4780:1:1::1:1f88/128 Scope:Global
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:20113 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9810 errors:0 dropped:3 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:23659654 (23.6 MB)  TX bytes:917246 (917.2 KB)

venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.224.2.128  P-t-P:10.224.2.128  Bcast:10.224.2.128  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1

当我访问http://31.220.49.197Apache 时,它​​无法为我提供 django 应用程序。当我这样做时,service apache2 restart一切都正常,我做错了什么?此配置适用于我的其他应用程序。

答案1

我遇到了同样的问题,但幸运的是,在深入研究之后阿帕奇设置我能够解决这个问题。

这是我的 apache 配置文件,即000-默认.conf它提供默认页面而不是我的应用程序。 笔记*:下面借助 OP apache 配置显示示例。

<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
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName 31.220.49.197
    WSGIDaemonProcess ts threads=25
    WSGIProcessGroup ts
    Alias /static /home/email-validator/static
    WSGIScriptAlias / /home/email-validator/index.wsgi

    # Set access permission
    <Directory />
            Allow from all
            Require all granted
    </Directory>

</VirtualHost>

在端口 80 上注释掉默认虚拟主机设置后,我的问题就解决了尽管我们仍然收到相同的错误日志:)

这意味着注释掉或删除整个默认/第一<VirtualHost *:80>部分将解决问题。

我目前使用的是 Ubuntu 14.4,从 12.4 升级后出现了这个问题。

相关内容