Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将https代理到http并启用ssl?_Http_Ssl_Nginx_Websocket_Nginx Reverse Proxy - Fatal编程技术网

如何将https代理到http并启用ssl?

如何将https代理到http并启用ssl?,http,ssl,nginx,websocket,nginx-reverse-proxy,Http,Ssl,Nginx,Websocket,Nginx Reverse Proxy,我已将我的应用程序配置为通过WebSocket(WS)协议进行通信,我希望通过https加载该应用程序。使用Nginx设置SSL后,我遇到以下错误: 混合内容:页面通过HTTPS加载,但尝试连接到不安全的WebSocket端点 经过一些研究,我可以使用Nginx中的redirect指令将HTTPS重定向到HTTP。但是,它通过HTTP(不带SSL)加载应用程序。我也想启用SSL 经过进一步研究,我尝试使用以下配置代理https: server { listen 443;

我已将我的应用程序配置为通过WebSocket(WS)协议进行通信,我希望通过
https
加载该应用程序。使用
Nginx
设置SSL后,我遇到以下错误:

混合内容:页面通过HTTPS加载,但尝试连接到不安全的WebSocket端点

经过一些研究,我可以使用
Nginx
中的
redirect
指令将
HTTPS
重定向到
HTTP
。但是,它通过
HTTP
(不带SSL)加载应用程序。我也想启用SSL

经过进一步研究,我尝试使用以下配置代理
https

server {
           listen 443;
           server_name my.server.com;

            ssl_certificate /etc/letsencrypt/live/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/privkey.pem; 
            include /etc/letsencrypt/options-ssl-nginx.conf; 
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
         
           ssl on;
           ssl_session_cache  builtin:1000  shared:SSL:10m;

        location / {
            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_set_header X-Forwarded-Proto $scheme;
            

            proxy_pass http://127.0.0.1:8000;
            proxy_read_timeout 86400;       
         
        }
    }

server {
    listen 8000;
       
    root /home/ubuntu/app;
    # Add index.php to the list if you are using PHP
    index index.html;

}
但是,我仍然得到相同的“混合内容”错误

启用SSL时,是否有办法将
HTTPS
代理/重定向到
HTPP

非常感谢

已更新

在我的应用程序中,我使用ws-endpoint进行如下设置:

const web3 = new Web3 ('ws://server-ip:7546')
注意:我不能使用
constweb3=newweb3('wss://server-ip:7546)

我已经更新了
Nginx
这样的配置,以代理上述ws端点:

server {
           listen 443;
           server_name my.app.com;

           root /home/ubuntu/app;
           index index.html;

           ssl_certificate /etc/letsencrypt/live/fullchain.pem;
           ssl_certificate_key /etc/letsencrypt/live/privkey.pem; 
           include /etc/letsencrypt/options-ssl-nginx.conf; 
           ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
         
           ssl on;
           ssl_session_cache  builtin:1000  shared:SSL:10m;


        location / {
            
           proxy_pass http://server-ip:7546;
           
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "Upgrade";
           proxy_set_header Host $host;

        }

    }
我在我的应用程序和代理通行证中使用相同的
服务器ip

有什么帮助吗?我在这里做错了什么?

在服务器配置中无法解决您遇到的错误


它来自于从HTTPS服务的站点内部访问普通HTTP或WS资源因此,这是一个由您提供的实际内容决定的问题,需要在那里解决。虽然您尝试的重定向可能最终会将不安全访问重定向到安全访问,但它不会改变首先需要进行不安全访问的情况,因为混合内容已经阻止了不安全访问。

有办法代理ws端点吗?在
location
指令中,我正在尝试
proxy\u passhttp://ws-endpoint
但还是不走运。@Yahya:这其实很常见,如何做到这一点。谢谢,你能检查一下问题的更新部分吗?@Yahya:请不要让你的问题成为移动目标。但是,由于您现在反向代理了websocket,您当然需要通过反向代理(即
wss://proxy/
而且不像以前那样直接。对不起,我找不到。您能再解释一下在哪里/如何使用
wss://proxy/