简体   繁体   English

https 不适用于我安装的 ssl(nginx 和 letencrypt)

[英]https is not working with my installed ssl (nginx & letsencrypt)

I have installed ssl certificate using letsencrypt in my nginx server.我已经在我的nginx服务器中使用 letencrypt 安装了 ssl 证书。 It works perfectly in the following domain: http://shajao.com它在以下域中完美运行: http : //shajao.com

Site gets redirected perfectly and ssl is working nicely with an A+ score in ssllabs.网站被完美重定向,ssl 在 ssllabs 中以 A+ 分数运行良好。

I followed this instruction: https://medium.com/@jnwarp/lets-encrypt-configure-nginx-with-a-perfect-score-on-ssl-labs-6fc10d2e4bf7我遵循了这条指令: https : //medium.com/@jnwarp/lets-encrypt-configure-nginx-with-a-perfect-score-on-ssl-labs-6fc10d2e4bf7

I tried to do the same thing on same server but different domain name but can't get it to work.我试图在同一台服务器上做同样的事情,但域名不同,但无法让它工作。 Basically ssl is not working.基本上 ssl 不起作用。 So when I hit the domain in browser it starts an infinite redirection loop.因此,当我在浏览器中访问域时,它会启动一个无限重定向循环。 So I stopped the http to https redirect and found that https is not working which gets the site redirected to http.所以我停止了 http 到 https 的重定向,发现 https 无法正常工作,导致站点重定向到 http。

My dns is managed using cloudflare and I tried turning off the ssl feature from there as well.我的 dns 是使用 cloudflare 管理的,我也尝试从那里关闭 ssl 功能。

Cloudflare ssl 关闭

My server code:我的服务器代码:

server {
    listen 80;
    listen [::]:80;
    server_name getcoursetube.com www.getcoursetube.com;
    root /media/6sense/www/getcoursetube.com;
    index index.html index.htm index.nginx-debian.html;
    #   return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    
    root /media/6sense/www/getcoursetube.com;
    index index.html index.htm index.nginx-debian.html;
    server_name getcoursetube.com www.getcoursetube.com;
    location / {
        try_files $uri$args $uri$args/ /index.html;
    }

    error_log /media/6sense/www/getcoursetube.com/logs/error.log;
    access_log /media/6sense/www/getcoursetube.com/logs/access.log;
    
    #WARNING: Please read before adding the lines below!
    add_header Strict-Transport-Security "max-age=31536000; 
    includeSubDomains" always;
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;

    ssl_certificate /etc/letsencrypt/live/getcoursetube.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/getcoursetube.com/privkey.pem;
    ssl_trusted_certificate /etc/nginx/ssl/chain.pem;
}

After spending hours, I tested my certificate on DigiCert.花了几个小时后,我在 DigiCert 上测试了我的证书。 And found that DigiCert is showing a SSL certificate that is issued by Cloudflare.并发现 DigiCert 显示的是 Cloudflare 颁发的 SSL 证书。

I turned off SSL from Cloudflare but it didn't work.我从 Cloudflare 关闭了 SSL,但它没有用。 So I had to quit Cloudflare.所以我不得不退出 Cloudflare。 I removed my site from Cloudflare and managed my DNS through GoDaddy (from where I purchased my domain).我从 Cloudflare 中删除了我的网站,并通过 GoDaddy(从那里我购买了我的域)管理了我的 DNS。 And it worked perfectly.它工作得很好。

Let me know if anybody has a better answer and made it work through Cloudflare as well.如果有人有更好的答案并通过 Cloudflare 使其工作,请告诉我。

Update:更新:

I readded my domain on Cloudflare and set SSL to full mode in Cloudflare.我在 Cloudflare 上阅读了我的域,并在 Cloudflare 中将 SSL 设置为完整模式。 Removed the redirection code from Nginx server configuration and enabled always https on Cloudflare.从 Nginx 服务器配置中删除了重定向代码,并在 Cloudflare 上始终启用 https。 And everything started working perfectly一切都开始完美运行

对我来说,原因是我没有允许到我的实例上的端口 443 的入站流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM