相關問題參考:
透過 Apache log 可看看出目前 mod_wsgi (Web Server Gateway Interface [Python])的版本為何?
如 Python 3.9 的 wsgi 4.7.1 另 Python 3.12 則為 4.9.4 ,如下 log 所示:
Apache/2.4.62 (Oracle Linux Server) OpenSSL/3.2.2 mod_auth_gssapi/1.6.3 mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
Apache/2.4.62 (Oracle Linux Server) OpenSSL/3.2.2 mod_auth_gssapi/1.6.3 mod_wsgi/4.9.4 Python/3.12 configured -- resuming normal operations
相關資訊可以透過 dnf info 取得
[root@Oracle9 conf.modules.d]# dnf info mod_wsgi
Last metadata expiration check: 1:33:33 ago on Sun 27 Apr 2025 10:55:14 AM CST.
Available Packages
Name : mod_wsgi
Version : 4.7.1
Release : 11.el9
Architecture : src
Size : 705 k
Source : None
Repository : ol9_appstream
Summary : A WSGI interface for Python web applications in Apache
URL : https://modwsgi.readthedocs.io/
License : ASL 2.0
Description : The mod_wsgi adapter is an Apache module that provides a WSGI compliant
: interface for hosting Python based web applications within Apache. The
: adapter is written completely in C code against the Apache C runtime and
: for hosting WSGI applications within Apache has a lower overhead than using
: existing WSGI adapters for mod_python or CGI.
[root@Oracle9 conf.modules.d]# dnf info python3.12-mod_wsgi
Last metadata expiration check: 1:34:08 ago on Sun 27 Apr 2025 10:55:14 AM CST.
Installed Packages
Name : python3.12-mod_wsgi
Version : 4.9.4
Release : 2.el9
Architecture : x86_64
Size : 1.1 M
Source : python3.12-mod_wsgi-4.9.4-2.el9.src.rpm
Repository : @System
From repo : ol9_appstream
Summary : A WSGI interface for Python web applications in Apache
URL : https://modwsgi.readthedocs.io/
License : ASL 2.0 and CC-BY
Description : The mod_wsgi adapter is an Apache module that provides a WSGI compliant
: interface for hosting Python based web applications within Apache. The
: adapter is written completely in C code against the Apache C runtime and
: for hosting WSGI applications within Apache has a lower overhead than using
: existing WSGI adapters for mod_python or CGI.
指定安裝
# dnf install python3.12-mod_wsgi.x86_64
切換作業系統所使用的 Python 版本.
[root@Oracle9 conf.modules.d]# alternatives --config python3
There are 2 programs which provide 'python3'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/python3.12
2 /usr/bin/python3.11
Enter to keep the current selection[+], or type selection number:
[root@Oracle9 conf.modules.d]# python -V
Python 3.12.5
[root@Oracle9 conf.modules.d]# cat /opt/privacyidea/requirements.txt | more
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements.txt
#
alembic==1.14.1 \
--hash=sha256:1acdd7a3a478e208b0503cd73614d5e4c6efafa4e73518bb60e4f2846a37b1c5 \
--hash=sha256:496e888245a53adf1498fcab31713a469c65836f8de76e01399aa1c3e90dd213
# via flask-migrate
==> mod_wsgi-py312.cpython-312-x86_64-linux-gnu.so
# cp mod_wsgi-py312.cpython-312-x86_64-linux-gnu.so /etc/httpd/modules/
# vi /etc/httpd/conf.modules.d/10-wsgi-python3.conf
[root@Oracle9 httpd]# cat /etc/httpd/conf.modules.d/10-wsgi-python3.conf
# NOTE: mod_wsgi_python3 can not coexist in the same apache process as
# mod_wsgi (python2). Only load if mod_wsgi is not already loaded.
<IfModule !wsgi_module>
#LoadModule wsgi_module modules/mod_wsgi_python3.so
LoadModule wsgi_module modules/mod_wsgi-py312.cpython-312-x86_64-linux-gnu.so
</IfModule>
Apache log
=> Apache/2.4.62 (Oracle Linux Server) OpenSSL/3.2.2 mod_auth_gssapi/1.6.3 mod_wsgi/5.0.2 Python/3.12 configured -- resuming normal operations
[root@Oracle9 httpd]#
PrivacyIDEA 整合 Apache + mod_wsgi 能否正常運行
要確定 Apache 內的 privacyidea.conf 是否正確.
# vi /etc/httpd/conf.d/privacyidea.conf