2013-05-14 103 views
0

我使用安裝了apache2和mod_wsgi的Ubuntu 12.04。 我想在我的本地計算機中使用bottlepy和php。 我知道這樣的問題已被其他人問到,如Apache mod_wsgi and php in the same domain。 但有人建議我提出一個新的問題,因爲我的問題可能會有所不同。在同一臺計算機上使用瓶裝和php

我已經改變/etc/apache2/sites-available/default到這一點:

<VirtualHost *:80> 
    ServerAdmin [email protected] 

    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。通過使用

sudo a2ensite default 
sudo service apache2 restart 

我的PHP腳本預期仍在工作

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) 

我已經做到使配置生效:我有kokoro.wsgi其中包含此腳本的同一目錄下。但是,每當我不知道如何訪問我的瓶頸腳本。

我也嘗試刪除的/etc/apache2/sites-available/default PHP的一部分,所以它僅由

<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> 

但我仍然不能得到bottlepy工作。它只是簡單地顯示404沒有找到。

任何人都有相同的經歷嗎?如何使它工作? 謝謝。

+0

您使用什麼URL訪問PHP站點以及Python站點的內容?根據你所顯示的,Python站點應該被訪問爲'http:// oraiso/kokoropy'。那是你正在使用的? 'oraiso'是否爲主機解決,或者您是否應該使用ServerName的FQDN。 – 2013-05-15 00:41:02

+0

我想php和oraiso python的本地主機 – goFrendiAsgard 2013-05-15 02:47:59

+0

但是你使用Python網站的確切URL是什麼?你沒有回答這個問題。 – 2013-05-15 06:54:44

回答

0

問題已解決。 首先,我改變httpd.conf中設置(或在我的情況/etc/apache2/sites-available/default)n要這樣:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    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

相關問題