Saya mencoba meng-host aplikasi WSGI (ditulis dalam webpy, dihosting di Apache) di server Ubuntu. Setiap kali saya menjalankan aplikasi saya, respons JSON diunduh alih-alih ditampilkan di browser. Namun aplikasi yang sama berfungsi dengan baik di localhost. Berikut kode aplikasi WSGI (diambil dari http://library.linode.com/frameworks/webpy/ubuntu-10.04-lucid) -
import web
import os
import sys
app_path = os.path.dirname(__file__)
sys.path.append(app_path)
os.chdir(app_path)
urls = ('/(.*)', 'hello')
web.debug = False # You may wish to place this in a config file
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc() # needed for running with apache as wsgi
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
Pengaturan konfigurasi Apache saya adalah -
WSGIScriptAlias /project /var/www/mywebsite.com/htdocs/project/main.py
<Directory /var/www/mywebsite.com/htdocs/project>
Order deny,allow
Allow from all
SetHandler wsgi-script
Options ExecCGI
</Directory>
Kalau dari browser, saya buka www.mywebsite.com/project/ lalu ada file dengan tulisan "Halo, Dunia!" tertulis di dalamnya diunduh.
Namun, ketika saya membuka www.mywebsite.com/project lalu saya mendapat pesan "Tidak Ditemukan"