I've got my Apache server setup and it is handling Flask responses via mod_wsgi. I've registered the WSGI script via the alias:
[httpd.conf]
WSGIScriptAlias /service "/mnt/www/wsgi-scripts/service.wsgi"
I've added the corresponding WSGI file at the above path:
[/mnt/www/wsgi-scripts/service.wsgi]
import sys
sys.path.insert(0, "/mnt/www/wsgi-scripts")
from service import application
And I have a simple test Flask Python script that provides the service module:
[/mnt/www/wsgi-scripts/service.py]
from flask import Flask
app = Flask(__name__)
@app.route('/')
def application(environ, start_response):
status = '200 OK'
output = "Hello World!"
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
@app.route('/upload')
def upload(environ, start_response):
output = "Uploading"
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
if __name__ == '__main__':
app.run()
When I go to my website URL [hostname]/service it works as expected and I get "Hello World!" back. The problem is that I don't know how to get other routes to work like, like 'upload' in the example above. This works fine in standalone Flask but under mod_wsgi I'm stumped. The only thing I can imagine is registering a separate WSGI script alias in the httpd.conf for each endpoint I want, but that takes away Flask's fancy routing support. Is there a way to make this work?
/service/upload
? You might be pleasantly surprised. – Burhan Khalid