server {
listen 443 ssl http2;
server_name test.abc.cn;
root /code/test;
# 证书路径和名称
ssl_certificate "n.pem";
ssl_certificate_key "n.key";
# 以下这个两个参数通常搭配使用
# 在建立完ssl握手后,如果断开连接,在session_timeout时间内再次连接不会重复请求
# 1m 表示开启1M大小的空间
ssl_session_cache shared:SSL:1m;
# ssl连接断开后的超时时间 - 1400m表示1440分钟,也就是24小时
ssl_session_timeout 1440m;
# 使用的 TLS 版本协议
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# 配置加密算法
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;
location / {
index index.html index.php;
autoindex off;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
# 这样可以全栈做成 https
server {
listen 80;
server_name test.abc.cn;
root /code/test;
location / {
index index.html index.php;
autoindex off;
}
# 请求PHP
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
# http 转 https
return 302 https://$server_name$request_uri;
# 或
# rewrite ^(.*)$ https://$host$1 permanent;
}
Nginx实现https的简单例子
最新推荐文章于 2022-08-27 10:30:00 发布