Python On Apache Web Server



In my earlier post we have gone thru step by step instructions to install Apache web server from scratch and host https enabled website into it. In this blog we will go thru the step by step instructions to host Python Flask APIs in Apache Web server. This is a requirement when you want to integrate front end Application(Angular SPA) with Azure AD because Angular SPA should call API hosted in Https Endpoint to work with Azure AD. In the production environment you can not use Flask to host your API and you definitely need a production web server like Apache or Gunicorn. Flask is good for development purpose but when you move to production you need to host it in Web server. Here is the example Architecture where it can be helpful.

  • Lars is a web server-log toolkit for Python. That means you can use Python to parse log files retrospectively (or in real time) using simple code, and do whatever you want with the data—store it in a database, save it as a CSV file, or analyze it right away using more Python. Lars is another hidden gem written by Dave Jones.
  • The modwsgi package provides an Apache module that implements a WSGI compliant interface for hosting Python based web applications on top of the Apache web server. Installation of modwsgi from source code can be performed in one of two ways. The first way of installing modwsgi is the traditional way that has been used by many software packages.

Step 1.Deploy Mod_ssl and apache web server. Please refer to my earlier post.

Use the Debian package manager to install the apache2 package: sudo apt update && sudo apt -y install apache2 After installing Apache, the operating system automatically starts the Apache server. Overwrite the Apache web server default web page with the following command.

Step 2: Install Mod_wsgi module. Lagu kaulah ibuku cinta kasihku.

Vulnerabilities

Please note that mod_wsgi module is required to host Flask API into Apache web server.

Step 3:Perform Module configuration.

Python On Apache Web Server Download

Add the below lines in the ssl.cnf ( SSL config file).Please refer to my earlier post to know what is ssl.cnf’s role here.

Step 3: Test the API call my using https://serverhostname/apiname. It should work perfectly.

Hope this post was useful.

Python On Apache Server

The Apache HTTP Server is a widely deployed web serverthat can be used in combination with a WSGI module, such as mod_wsgi or astand-alone WSGI server to run Python web applications.

Why is the Apache HTTP Server important?

Apache remains the most commonly deployed web server with a reign of20+ years. Its wide usage contributes to the large number of tutorialsand open source modules created by developers for anyone to use.

Apache's development began in mid-1994 as a fork of theNCSA HTTP Server project.By early 1996, Apache overtook the previously dominant but suddenly stagnantNCSA server as NCSA's progress stalled due to signficantly reduceddevelopment attention.

The Apache HTTP Server is an implementation of the web server concept. Learn how these pieces fit together in the deployment chapter or view the table of contents for all topics.

Apache HTTP Server resources

  • Theofficial project documentation pagecontains a section with How-Tos and Tutorials to handle authentication,security and dynamic content.

  • Reverse proxies showshow to set up Apache as a reverse proxy using mod_proxy.

  • Deploy Django on Apache with Virtualenv and mod_wsgiprovides instructions for what packages to install to get Apache upand running with mod_wsgi on Ubuntu.

  • Detecting Bots in Apache & Nginx Logsis a great tutorial for filtering out the significant traffic generatedby web crawlers and bots when using Apache HTTP Server logs for trafficanalytics.

  • Apache vs Nginx: Practical Considerationsis a good comparison post that covers the differences between Apache andNginx such as how they handle connections and serve content.

  • Monitoring Apache web server performancegives a really nice overview of metrics to watch when you are usingApache as your web server.

  • Web Performance 101: HTTP Headerscovers the gamut of HTTP headers and shows how they can impact performancebased on your configuration.

  • Apache Web Server on Ubuntu 14.04 LTSexplains how to install Apache on Ubuntu 14.04, which is still a supportedrelease. Note however, do not install mod_python because it is now insecureand made obsolete by mod_wsgi and WSGI servers.

Continue learning about web servers or move to a new topic?

What runs a Python application execute on the server?