我正在開發一個 RedHat Centos 7 盒子。我已將 python 3.9.2 安裝到/opt/python3.9. 我正在將我的 dJango 服務器轉移到生產環境中,并選擇將 Apache(我已安裝httpd-devel)與 mod_wsgi 一起使用。我正在按照他們的說明進行操作,以確保正確配置。
我安裝了apache:
sudo yum install httpd
sudo yum install httpd-devel
然后
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/tags/4.9.2.tar.gz
mv 4.9.2.tar.gz ./mod_wsgi_4.9.2.tar.gz
tar xvfz mod_wsgi-4.9.2.tar.gz
cd mod_wsgi*
./configure --with-python=/opt/python3.9/bin/python39
make
sudo make install
都沒有錯誤。
sudo systemctl enable httpd
sudo systemctl start httpd
但是,一旦我嘗試在這里使用演示(這基本上需要添加一個 conf 檔案到/etc/httpd/conf.d/, calledwsgi.conf和一個回應檔案到/var/www/html/, called test_wsgi.py,然后重新啟動 apache),它就會拋出一個錯誤并告訴我檢查journalctl -xe.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: AH00526: Syntax error on line 2 of /etc/httpd/conf.d/wsgi.conf:
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Unit httpd.service entered failed state.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal sudo[11888]: pam_unix(sudo:session): session closed for user root
我有 95% 的把握,如果我按照這里的建議進行操作,它將為 python 2.7 編譯 mod_wsgi 而我不想使用 python2.7 ...這就是我為 python 3.9.2 編譯 mod_wsgi 的原因。
如果我嘗試使用我的 django.conf 檔案而不是我在演示中鏈接的檔案,我會得到一個不同的錯誤,它可能對 slue 更有幫助:
httpd.conf: Syntax error on line 3 of /etc/httpd/conf.d/django.conf: Cannot load /usr/lib64/httpd/modules/mod_wsgi.so into server: libpython3.9.so.1.0: cannot open shared object file: No such file or directory
第 3 行是:
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
輸出ldd /usr/lib64/httpd/modules/mod_wsgi.so:
[ec2-user@ip-172-31-18-8 ~]$ ldd /usr/lib64/httpd/modules/mod_wsgi.so
linux-vdso.so.1 (0x00007ffd7b50d000)
libpython3.9.so.1.0 => /opt/python39/lib/libpython3.9.so.1.0 (0x00007ff0ebf85000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007ff0ebd4e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff0ebb30000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff0eb92c000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007ff0eb729000)
libm.so.6 => /lib64/libm.so.6 (0x00007ff0eb3e9000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff0eb03e000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff0ec781000)
我可以驗證 /opt/python39/lib/libpython3.9.so.1.0 存在并且我有它LD_RUN_PATH and LD_LIBRARY_PATH variables
輸出sudo apachectl -V:
Server version: Apache/2.4.53 ()
Server built: Apr 12 2022 12:00:44
Server's Module Magic Number: 20120211:124
Server loaded: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Compiled using: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_PROC_PTHREAD_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
謝謝您的幫助。我有點忙,所以我會盡快回復您。
uj5u.com熱心網友回復:
你看到這個錯誤...
libpython3.9.so.1.0: cannot open shared object file: No such file or directory
...因為httpd不知道它應該/opt/python3.9/lib尋找必要的共享庫。有幾種方法可以解決這個問題:
-rpath鏈接模塊時設定。這在編譯的二進制檔案中嵌入了庫的路徑。您可以通過
make在目錄中像這樣運行來設定它mod_wsgi-4.9.2:make LDFLAGS='-L/opt/python3.9/lib -Wl,-rpath,/opt/python3.9/lib'設定
LD_LIBRARY_PATH在httpd的環境中。這提供httpd了一個額外的目錄串列來搜索共享庫。我們可以這樣測驗:LD_LIBRARY_PATH=/opt/python3.9/lib httpd -DFOREGROUND要持久設定它,您需要自定義
httpd服務單元:跑
systemctl edit httpd在出現的編輯器中,添加以下內容:
[Service] Environment=LD_LIBRARY_PATH=/opt/python3.9/lib這會創建
/etc/systemd/system/httpd.service.d/override.conf.運行
systemctl daemon-reload以重繪 單元檔案的快取版本。重新啟動您的
httpd服務。
/etc/ld.so.conf.d/python3.9.conf通過使用以下內容創建來編輯全域庫搜索路徑 :/opt/python3.9/lib然后運行:
ldconfig
上述任何選項都應該為您運行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/488106.html
標籤:python-3.x 阿帕奇 centos7 mod-wsgi
