設置 | 登錄 | 註冊

作者共發了8篇帖子。

CentOS7自帶的nginx-1.20.1是支持HTTP/2和TLS1.3的

1樓 巨大八爪鱼 2024-7-3 20:57
軟件包名稱:nginx-1.20.1-10.el7.x86_64

CentOS7默認開啟了HTTP/2,但沒有開啟TLS1.3,以及IE6和IE8的https訪問。

開啟方法:

ssl_ciphers HIGH:!aNULL:!MD5;改為ssl_ciphers HIGH:MEDIUM:!MD5:!RC4;

添加一行ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;

然後sudo systemctl restart nginx重啟伺服器即可。

2樓 巨大八爪鱼 2024-7-3 21:44
nginx目前已經有HTTP/3模塊了(實驗性模塊),但apache還沒做這種模塊。
3樓 巨大八爪鱼 2025-3-10 14:18
[oct1158@cxywxvxep temp]$ nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
[oct1158@cxywxvxep temp]$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

居然用的不是同一個openssl。。。
巨大八爪鱼今天突然發現這種方法失效了,sslv3不行了,ie6無法訪問https。
4樓 巨大八爪鱼 2025-3-10 15:17
2025年3月10日,突然發現該方法失效,IE6無法訪問https。
因為前幾天剛把/opt目錄下沒有用的自編譯的httpd2.4.59和openssl1.1.1w(支持SSLv3)刪除了。
以前nginx可能碰巧引用到了自編譯的openssl1.1.1w的庫文件,所以IE6可以正常訪問https。
現在沒有openssl1.1.1w了,nginx可能就跑去引用自身的不支持SSLv3的openssl1.1.1k了,IE6就無法訪問了。

$ nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: (略)

$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

由此可見nginx自帶了一個openssl1.1.1k,不是centos7系統裏面的那個openssl1.0.2k。
5樓 巨大八爪鱼 2025-3-10 16:49
【手工編譯安裝nginx(裏麵包含支持ssl3的openssl)】
cd ~
wget https://nginx.org/download/nginx-1.27.4.tar.gz
tar xf nginx-1.27.4.tar.gz
wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
tar xf openssl-1.1.1w.tar.gz

cd nginx-1.27.4
./configure --prefix=/opt/nginx-1.27.4 --with-http_ssl_module --with-openssl=../openssl-1.1.1w --with-openssl-opt="enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers" --with-http_v2_module
make
sudo make install

安裝完成後,/opt下只有一個nginx-1.27.4文件夾,沒有單獨的openssl文件夾。
查看編譯出來的nginx可執行文件的版本:
$ /opt/nginx-1.27.4/sbin/nginx -V
nginx version: nginx/1.27.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1w  11 Sep 2023
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx-1.27.4 --with-http_ssl_module --with-openssl=../openssl-1.1.1w --with-openssl-opt='enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers' --with-http_v2_module
可見openssl是被直接打包到nginx可執行文件裏面了。

【測試】
啟動:sudo /opt/nginx-1.27.4/sbin/nginx
重啟:sudo /opt/nginx-1.27.4/sbin/nginx -s reload
關閉:sudo /opt/nginx-1.27.4/sbin/nginx -s stop

【開啟https(支持IE6)】
修改/opt/nginx-1.27.4/conf/nginx.conf文件,取消註釋有listen 443的那個server塊。
把ssl_certificate和ssl_certificate_key改成自己的證書文件。
ssl_ciphers  HIGH:!aNULL:!MD5;改成ssl_ciphers HIGH:MEDIUM:!MD5:!RC4;
下面加一句ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
重啟nginx伺服器即可用IE6訪問。

【開啟http2】
server_name  localhost;下面加一句http2 on;
重啟nginx伺服器。

【開機啟動(這個方法只能用於CentOS系統)】
關閉nginx伺服器:sudo /opt/nginx-1.27.4/sbin/nginx -s stop
創建/usr/lib/systemd/system/opt_nginx.service文件,內容如下:
[Unit]
Description=opt_nginx
After=network.target

[Service]
Type=forking
ExecStartPre=/opt/nginx-1.27.4/sbin/nginx -t
ExecStart=/opt/nginx-1.27.4/sbin/nginx
ExecReload=/opt/nginx-1.27.4/sbin/nginx -s reload
ExecStop=/opt/nginx-1.27.4/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

啟動nginx伺服器:sudo systemctl start opt_nginx
設置為開機啟動:sudo systemctl enable opt_nginx

【其他設置】
設置上傳文件的最大尺寸:
http塊內,server塊外添加
# set maximum post size
client_max_body_size 20m;
6樓 巨大八爪鱼 2025-3-10 16:50
【PHP配置】
server塊的location /內:
index index.html index.htm index.php;
location /外的下方:
include /home/oct1158/config/nginx/php-fpm.conf;

php-fpm.conf文件內容:
location ~* \.php$ {
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
7樓 巨大八爪鱼 2025-3-12 11:43

對於fedora41系統,php-fpm.conf裏面的fastcgi_pass 127.0.0.1:9000;要改成
fastcgi_pass php-fpm;
另外再新建一個php-upstream.conf,內容如下:
upstream php-fpm {
        server unix:/run/php-fpm/www.sock;
}

 

/opt/nginx-1.27.4/conf/nginx.conf裏面
頂部新加一句user nginx;
http塊內,server塊外的上方添加一句include /home/oct1158/config/nginx/php-upstream.conf;

這是因為fedora41系統的php-fpm服務不是用的9000端口,而是用的unix socket文件。

sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl restart opt_nginx

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
©2010-2025 Purasbar Ver3.0 [手機版] [桌面版]
除非另有聲明,本站採用知識共享署名-相同方式共享 3.0 Unported許可協議進行許可。