Building an HTTP server
Institute for Environmental and Spatial Analysis...University of North Georgia
Contents
1 Apache HTTP server
Using Apache HTTP Server on Microsoft Windows
Extract Apache24
to C:\Apache24
.
C:\Apache24\bin\httpd.exe
: Main daemon programC:\Apache24\conf
: Configuration files
Start the server.
C:
cd \Apache24\bin
httpd.exe
Add Include conf/custom.conf
to conf/httpd.conf
.
conf/custom.conf
DocumentRoot "/tmp"
<Directory "/tmp">
Require all granted
</Directory>
2 WSGI
2.1 uwsgi
Install uwsgi for Python
pip install uwsgi
2.2 On a supported platform
Set up Apache
LoadModule proxy_module lib64/httpd/modules/mod_proxy.so
LoadModule proxy_uwsgi_module lib64/httpd/modules/mod_proxy_uwsgi.so
ProxyPass /webapp/ uwsgi://localhost:8000/
Write a WSGI application using Bottle
from bottle import default_app
application = default_app()
Run the application as a uwsgi instance
uwsgi --socket :8000 --wsgi-file webapp.py
3 Run Python scripts as CGI
custom.conf
DocumentRoot "/tmp"
<Directory "/tmp">
Require all granted
Options ExecCGI
AddHandler cgi-script .cgi
</Directory>
C:\tmp\hello.py
#!C:/opt/Python310/python.exe
print("Content-Type: text/plain\n\nHello World!\n")
4 Hiding the CGI script name
custom.conf
LoadModule rewrite_module modules/mod_rewrite.so
DocumentRoot "/tmp"
<Directory "/tmp">
Require all granted
Options ExecCGI
AddHandler cgi-script .py
</Directory>
RewriteEngine on
RewriteCond %{REQUEST_URI} "!^/webapp.py"
RewriteRule "^(/.*)$" "/webapp.py$1"