1

我使用安装了 apache2 和 mod_wsgi 的 ubuntu 12.04。我想在我的本地计算机上使用 Bottlepy 和 php。我知道其他人已经问过这样的问题,例如Apache mod_wsgi 和 php 在同一个域中。但是有人建议我提出一个新问题,因为我的问题可能会有所不同。

我已经/etc/apache2/sites-available/default变成了这样:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

<VirtualHost *>
    DocumentRoot /home/gofrendi/workspace/kokoropy
    ServerName oraiso
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
    <Directory /home/gofrendi/workspace/kokoropy>
        WSGIProcessGroup kokoropy
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

第一个虚拟主机用于 PHP,第二个用于 Bottlepy。我把我的瓶子应用程序放在/home/gofrendi/workspace/kokoropy. 我kokoro.wsgi在包含此脚本的同一目录中:

import os
sys.path = [os.path.dirname(__file__)] + sys.path

from kokoropy import kokoro_init
PWD = os.path.dirname(os.path.abspath(__file__))
APP_DIRECTORY = 'applications'
APPLICATION_PATH = os.path.join(PWD, APP_DIRECTORY)    
application = kokoro_init(application_path = APPLICATION_PATH, run = False)

我确实通过使用启用了配置

sudo a2ensite default
sudo service apache2 restart

我的 PHP 脚本仍然按预期工作。但是,每当我不知道如何访问我的 Bottlepy 脚本时。

我还尝试删除 的 PHP 部分/etc/apache2/sites-available/default,使其仅包含

<VirtualHost *>
    DocumentRoot /home/gofrendi/workspace/kokoropy
    ServerName oraiso
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
    <Directory /home/gofrendi/workspace/kokoropy>
        WSGIProcessGroup kokoropy
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

但我仍然无法获得瓶装工作。它只是简单地显示 404 未找到。

有没有人有同样的经历?如何让它发挥作用?谢谢。

4

1 回答 1

1

问题已解决。首先,我将 httpd.conf 设置(或在我的情况下/etc/apache2/sites-available/default)更改为:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>


    # THIS IS WHERE I START TO EDIT IT:
    # It tells apache about wsgi existance
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5   
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi
    <Directory /home/gofrendi/workspace/kokoropy>
        WSGIProcessGroup kokoropy
        WSGIApplicationGroup %{GLOBAL}
        Options ExecCGI
        Order deny,allow
        Allow from all
    </Directory>

</VirtualHost>

这个配置说localhost/kokoropy应该由wsgi处理。

我的 wsgi 脚本位于/home/gofrendi/workspace/kokoropy/kokoro.wsgi. kokoro.wsgi 内容如下:

import os, sys
os.chdir(os.path.dirname(__file__))
sys.path = [os.path.dirname(__file__)] + sys.path

from bottle import default_app
@route('/')
def index():
   return 'run with apache'
application = default_app()

如果你在访问bottlepy时发现内部服务器错误,但在访问php时没有发现错误,那可能是你wsgi的一些错误。只需打开 apache 日志(在我的情况下,它就在这里/var/log/apache2/error.log:)

于 2013-05-19T05:22:47.693 回答