問題
CentOS 7 默認安裝的 nginx 依賴 openssl 版本為 v1.0.2k (需要手動安裝最新版 nginx v1.20.2,支持openssl v1.0.2+)
uwsgi 默認依賴的 openssl 版本為 v1.1.1
mycli (cryptography,這個庫在 paramiko 里面用到
) 支持的 openssl 版本為 v1.1.0, v1.1.1,參見 https://cryptography.io/en/latest/installation/
所以 openssl 的版本問題會造成上述軟件沖突。
解決方案
0) 卸載默認安裝的 openssl
$ sudo yum remove openssl
1) 手動安裝 openssl v1.1.1
從 https://www.openssl.org/source/old/1.1.1/openssl-1.1.1.tar.gz 下載安裝包,編譯安裝,
$ tar --gzip -xf openssl-1.1.1.tar.gz $ cd openssl-1.1.1 $ ./config $ make $ sudo make install
創建 openssl 的系統軟鏈接,
$ sudo ln -fs /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 $ sudo ln -fs /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
2) 手動安裝 nginx
從 https://nginx.org/download/nginx-1.20.2.tar.gz 下載最新穩定版的 nginx,編譯安裝,
$ tar --gzip -xf nginx-1.20.2.tar.gz $ cd nginx-1.20.2 $ ./configure $ make $ sudo make install # 如果要刪除這個安裝版本,則先進入此文件夾,然后運行 $ sudo make uninstall
安裝完成后,默認安裝路徑在 /usr/local/nginx/sbin/nginx,默認配置文件路徑在 /usr/local/nginx/conf。
創建並編輯 nginx 的開機啟動文件 /lib/systemd/system/nginx.service,內容為,
[Unit]
Description=The NGINX HTTP and reverse proxy server After=syslog.target network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/usr/sbin/nginx -s reload ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
因為上述文件 nginx 可執行程序為 /usr/sbin/nginx,所以需要創建軟鏈接如下,
$ sudo ln -fs /usr/local/nginx/sbin/nginx /usr/sbin/nginx
手動安裝的 nginx 的配置文件路徑為 /usr/local/nginx/conf/nginx.conf,根據項目需求,編輯此文件即可。
注意,因為上述開機自啟動文件 nginx.service 文件中已經制定 PIDFile=/run/nginx.pid,所以需要在 nginx.conf 中做同樣的配置,如下,
... pid /run/nginx.pid; ...
設置 nginx 的開機啟動 ,
$ sudo systemctl enable nginx.service
重啟電腦。
(完)