Building an HTTP server

Dr. Huidae Cho
Institute for Environmental and Spatial Analysis...University of North Georgia

1   Apache HTTP server

Using Apache HTTP Server on Microsoft Windows

Extract Apache24 to C:\Apache24.

  • C:\Apache24\bin\httpd.exe: Main daemon program
  • C:\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

uwsgi; oh my!

2.1   uwsgi

The uWSGI project

Install uwsgi for Python

pip install uwsgi

Oops! Supported Platforms/Systems

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"

5   PythonAnywhere

https://www.pythonanywhere.com/