简体   繁体   English

使用 ZEA52C36203C5F99C32CE2442D5Z1B1 将 HTTP 重定向到 HTTPS nginx

[英]Redirect HTTP to HTTPS nginx with SSL

After a lot of tries, I succeed to add proper SSL from namecheap, that will secure my domain (with multiple ports).经过多次尝试,我成功地从 namecheap 添加了适当的 SSL,这将保护我的域(具有多个端口)。

I have some apps - that run on NGINX.我有一些应用程序 - 在 NGINX 上运行。 My droplet is of Digital Ocean.我的水滴是数字海洋。

So I have a few blocks with this configuration:所以我有这个配置的几个块:

#this is the default 80 port 
server {
#listen 80; # - will cause nginx complain on already in use. 
listen 443;

ssl on;

ssl_certificate /my/folder/forssl/my-domain_com_chain.crt;

ssl_certificate_key /home/projects/ssl-files/my-domain.com.key;

root /var/www/my-domain.com/so-ev;

server_name my-domain.com;

#all those tries didn't help
 #   return 301 https://so-ev-qa.shop$request_uri;
#return 301 https://$server_name$request_uri;
#rewrite ^(.*) https://so-ev-qa.shop$1 permanent;


}



server {

listen 26;

ssl on;

ssl_certificate /my/folder/forssl/my-domain_com_chain.crt;

ssl_certificate_key /home/projects/ssl-files/my-domain.com.key;

root /var/www/my-domain.com/html;

server_name my-domain.com;

}

server {

listen 3000 ;

ssl on;

ssl_certificate /my/folder/forssl/my-domain_com_chain.crt;

ssl_certificate_key /home/projects/ssl-files/my-domain.com.key;

root /var/www/my-domain.com/html2;

server_name my-domain.com;

}


server {
    listen 27;
     ssl on;

               
                ssl_certificate /my/folder/forssl/my-domain_com_chain.crt;

                ssl_certificate_key /home/projects/ssl-files/my-domain.com.key;

                server_name  my-domain.com;
                index index.html index.htm;
                access_log /var/log/nginx/bmiapp.log;
                error_log  /var/log/nginx/bmiapp-error.log error;

                location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $http_host;
                proxy_pass http://127.0.0.1:26;
                proxy_redirect off;
         }
}

Currently the problem is that it's not doing redirect from http to https.目前的问题是它没有从 http 重定向到 https。

While https://example.com is secured, http://example.com isn't.虽然https://example.com是安全的,但 http://example.Z4D236D9A2D102C5FE6AD1C50Z不是。

I am trying to do the simple redirecting action.我正在尝试执行简单的重定向操作。

All my tries ended unsuccessfully.我所有的尝试都以失败告终。

If I'm trying to add block for listen 80, it's complain about如果我试图为听 80 添加块,它会抱怨“已在使用中”。 All my other tries didn't work.我所有的其他尝试都没有奏效。

Help will be appreciated, I have spent on this SSL issues a lot of hours.帮助将不胜感激,我在这个 SSL 问题上花费了很多时间。

I found the problem.我发现了问题。

There was an old-client service that was running on the background.有一个旧客户端服务在后台运行。

We can use我们可以用

udo lsof -i:80

To get a clue获得线索

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

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