由於PID 1在Docker被佔用的問題,所以是無法以systemctl restart httpd來執行APACHE的

在Ubuntu 16.04中找到一個work around的方法,測試可在Docker中使用

sudo /etc/init.d/apache2 reload

由於想在DOCKER中執行WSGI 因此進行安裝測試python 3.8

安裝python 3.8

apt update
apt install software-properties-common
add-apt-repository ppa:deadsnakes/ppa
apt install python3.8

測試是否有完成安裝

python3.8 --version

安裝mod_wagi模組

apt-get update
apt-get install python libexpat1
apt-get update
apt-get install apache2 apache2-utils ssl-cert
apt-get install libapache2-mod-wsgi
/etc/init.d/apache2 reload

執行vi /var/www/html/wsgi_test_script.py檔案並增加以下程式

def application(environ,start_response):
    status = '200 OK'
    html = '<html>\n' \
           '<body>\n' \
           ' Hooray, mod_wsgi is working\n' \
           '</body>\n' \
           '</html>\n'
    response_header = [('Content-type','text/html')]
    start_response(status,response_header)
    return [html]

執行vi /etc/apache2/conf-available/mod-wsgi.conf 加入以下設定

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

設定網站並重啟Apache

a2enconf mod-wsgi
/etc/init.d/apache2 reload

進行測試

先以docker ps -l 查出80 port的映設port(此處為55001)

參考資料

DockerHub:

docker pull liusming/apacheu16:wsgi

Leave a Reply

Your email address will not be published. Required fields are marked *