GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare il modulo Apache mod_wsgi su Ubuntu 18.04 (Bionic)

Il modulo mod_wsgi Apache viene utilizzato per servire gli script Python su HTTP tramite il server Web Apache. Questo tutorial ti aiuta a come installare il modulo Apache mod_wsgi su Ubuntu 18.04 (Bionic Beaver).

Fase 1 – Prerequisiti

Accedi alla console del server Ubuntu 18.04 tramite SSH e installa alcuni pacchetti di prerequisiti sul sistema.

sudo apt-get update
sudo apt-get install python libexpat1 

Passaggio 2:installare il modulo mod_wsgi

Prima di iniziare, dovrai installare alcuni componenti Apache prerequisiti per poter lavorare con mod_wsgi. Puoi installare tutti i componenti richiesti semplicemente eseguendo il seguente comando:

sudo apt-get update
sudo apt-get install apache2 apache2-utils ssl-cert

Ora, installa il modulo mod_wsgi Apache eseguendo il seguente comando:

sudo apt-get install libapache2-mod-wsgi

Riavvia il servizio Apache per far funzionare mod_wsgi.

sudo systemctl restart apache2

Fase 3 – Configura Apache per WSGI

Quindi, crea uno script python da servire tramite il modulo mod_wsgi Apache.

sudo vi /var/www/html/wsgi_test_script.py

Aggiungi il seguente contenuto:

XHTML
12345678910 def application(environ,start_response):status ='200 OK' html ='\n' \ '\n' \ ' Evviva, mod_wsgi funziona\n' \ '\n' \ '\n' response_header =[('Content-type','text/html')] start_response(status,response_header) return [html]

Successivamente, è necessario configurare il server Apache per servire questo file tramite il protocollo HTTP. Creiamo un file di configurazione per servire lo script wsgi_test_script.py su un sub URL.

sudo nano /etc/apache2/conf-available/mod-wsgi.conf

Aggiungi il seguente contenuto:

WSGIScriptAlias /test_wsgi /var/www/html/wsgi_test_script.py

Dopo aver completato i passaggi precedenti, abilita mod-wsgi configurazione e riavvia il servizio Apache.

sudo a2enconf mod-wsgi
sudo systemctl restart apache2

Fase 4 – Test

L'installazione è ora pronta. Puoi testare lo script accedendo al seguente URL in un browser web.

 http://SERVER_IP/test_wsgi

Vedi sotto screenshot:


Ubuntu
  1. Come installare Apache su Ubuntu 18.04

  2. Come installare Apache su Ubuntu 20.04

  3. Come installare Joomla con Apache su Ubuntu 18.04

  4. Come installare Apache CouchDB su Ubuntu 18.04 LTS

  5. Come installare la GUI di Apache su Ubuntu 18.04 LTS

Come installare ModSecurity Apache su Ubuntu 20.04 LTS

Come installare Apache Tomcat su Ubuntu 20.04 LTS

Come installare Apache Tomcat su Ubuntu 18.04 Bionic Beaver

Come installare Apache CouchDB su Ubuntu 18.04 Bionic Beaver

Come installare ModSecurity Apache su Ubuntu 20.04

Come installare Apache su Ubuntu 22.04