First I added the following to the httpd.conf file to configure Apache:
<VirtualHost *:8081>
ServerAlias example.com
ServerAdmin cees@nortek-bv.nl
DocumentRoot c:/DATA/xampp/apache/htdocs
<Directory c:/DATA/xampp/apache/htdocs>
AuthType Basic
AuthName "Scour Server Login"
AuthUserFile c:/DATA/xampp/apache/passwords/.htpasswd
AllowOverride all
Require valid-user
</Directory>
WSGIScriptAlias /get_data c:/DATA/xampp/wsgi/get_data.wsgi
<Directory c:/DATA/xampp/wsgi>
Require all granted
</Directory>
</VirtualHost>
# Python WSGI interface module
<IfModule wsgi_module>
WSGIPythonHome "C:/Python27"
</IfModule>
Putting the rules in a 'VirtualHost' section allows us to configure differnent setups on other ports if required. The 'AuthType', 'AuthUserFile' and 'Require valid-user' enable a user-name / password security for the site. User-name and Password have to be entered in the '.htpasswd' file using the htpasswd utility. (Check the Authentication page in the Apache docs for details)
By setting the WSGIScriptAlias "/get_data" to the actual program path I can call the program by simply going to the URL www.my_site.com/get_data.
A very nice basic instruction on how to use the WSGI module and to process the requests is given on the WSGI Tutorial pages . What is particularly nice is the example where the program shows all values in the 'environ' dictionary of the WSGI application:
COMSPEC: C:\WINDOWS\system32\cmd.exe
CONTEXT_DOCUMENT_ROOT: C:/DATA/xampp/apache/htdocs
CONTEXT_PREFIX:
DOCUMENT_ROOT: C:/DATA/xampp/apache/htdocs
GATEWAY_INTERFACE: CGI/1.1
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: nl,en-US;q=0.7,en;q=0.3
HTTP_CONNECTION: keep-alive
HTTP_HOST: localhost:8081
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY
PATH_INFO: /
PATH_TRANSLATED: C:\DATA\xampp\apache\htdocs\index.html
QUERY_STRING: age=10&hobbies=software&hobbies=tunning
REMOTE_ADDR: ::1
REMOTE_PORT: 52609
REQUEST_METHOD: GET
REQUEST_SCHEME: http
REQUEST_URI: /myapp/?age=10&hobbies=software&hobbies=tunning
SCRIPT_FILENAME: C:/DATA/xampp/wsgi/hello_world.wsgi
SCRIPT_NAME: /myapp
SERVER_ADDR: ::1
SERVER_ADMIN: cees@nortek-bv.nl
SERVER_NAME: localhost
SERVER_PORT: 8081
SERVER_PROTOCOL: HTTP/1.1
SERVER_SIGNATURE:
SERVER_SOFTWARE: Apache/2.4.12 (Win64) mod_wsgi/3.4 Python/2.7.9
SystemRoot: C:\WINDOWS
WINDIR: C:\WINDOWS
mod_wsgi.application_group: Lenovo-Cees.nortek.local:8081|/myapp
mod_wsgi.callable_object: application
mod_wsgi.enable_sendfile: 0
mod_wsgi.handler_script:
mod_wsgi.input_chunked: 0
mod_wsgi.process_group:
mod_wsgi.request_handler: wsgi-script
mod_wsgi.script_reloading: 1
mod_wsgi.version: (3, 4)
wsgi.errors: <mod_wsgi.Log object at 0x0000000004054DF0>
wsgi.file_wrapper: <built-in method file_wrapper of mod_wsgi.Adapter object at 0x0000000002A4BC60>
wsgi.input: <mod_wsgi.Input object at 0x0000000002A52470>
wsgi.multiprocess: False
wsgi.multithread: True
wsgi.run_once: False
wsgi.url_scheme: http
wsgi.version: (1, 0)
That's a wealth of information ! When you look at this you immediately get a grip on the power of the WSGI framework.
Geen opmerkingen:
Een reactie posten