刚刚配置好https证书,可以实现访问,可是发现个问题输入网址直接是到http网站而非https,每次需要输入https那也真麻烦
用我自己的网站实验:http://thelemon.icu/ 直接跳转到https://thelemon.icu/
步骤:修改nginx.conf
server {
listen 80;
server_name thelemon.icu www.thelemon.ciu;
#强转https
rewrite ^(.*)$ https://$host$1 permanent;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#此处要修改为你自己的地址
proxy_pass http://ip:8090;
}
}
#HTTPS server
server {
#ssl端口
listen 443 ssl;
server_name thelemon.icu;
#指定PEM格式的证书文件
# cert 证书文件地址
ssl_certificate cert/4192523_thelemon.icu.pem;
#指定PEM格式的私钥文件
ssl_certificate_key cert/4192523_thelemon.icu.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#此处要修改为你自己的地址
proxy_pass http://ip:8090;
}
}