阿里云域名配置https(免费版) Nginx配置证书并将http请求转发到https
-
登录阿里云找到自己的域名
-
server {
-
listen 443 ssl;
-
server_name 要设置的域名;
-
root html;
-
index index.html index.htm;
-
ssl_certificate .pem后缀的证书位置,如:/usr/local/nginx/conf/cert/3478976_abc.baidu.com.pem;
-
ssl_certificate_key .key后缀的证书位置,如:/usr/local/nginx/conf/cert/3478976_abc.baidu.com.key;
-
ssl_session_timeout 5m;
-
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
-
ssl_prefer_server_ciphers on;
-
location ~*^.+$ {
-
proxy_redirect off;
-
proxy_set_header Host $host;
-
proxy_set_header X-real-ip $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
proxy_pass 请按自身情况设置;
-
}
-
}
-
-
#可选配置,配置http重定向到https
-
server
-
{
-
listen 80;
-
server_name 要设置的域名;
-
rewrite ^(.*)$ https://$host$1 permanent; #将所有http请求通过rewrite重定向到https。
-
location ~*^.+$ {
-
proxy_redirect off;
-
proxy_set_header Host $host;
-
proxy_set_header X-real-ip $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
proxy_pass 请按自身情况设置;
-
}
-
}
-
root@iZj6cd6z27o4s242bij2ylZ:/usr/local/nginx/sbin$ ./nginx -s reload
-
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:112
-
root@iZj6cd6z27o4s242bij2ylZ:/usr/local/nginx/sbin$
参考: https://blog.****.net/u011294519/article/details/84933823
https://blog.****.net/a873217486/article/details/106097855
https://blog.****.net/weixin_38111957/article/details/81283121