开发者社区> 问答> 正文

nginx反向代理https的问题 - nginx报错

我使用的软件是nginx1.8.1。

想在网站服务器前端新增一台https的反向代理。

具体情况是:前端代理服务器只接受https的443请求,然后转发给后面实体服务器处理,实体服务器已经配置好ssl证书,可以正常访问https的页面,请问这样情况应该怎么配置。

我自己尝试加了一个upstream,实体服务器ip地址:443,然后配置一个server,之中域名监听443,然后proxy_pass 转发到那个443的upstream,然而并不能这么配。

 

请教下大大怎么配置

展开
收起
montos 2020-05-31 13:00:20 831 0
1 条回答
写回答
取消 提交回答
  • 没试过https,只能提示一下后端的服务器监听的servername是什么?送到后端的host参数会不会是代理机的ip?######通常都是代理服务器跟实际服务器直接用http,######

    参考 https://www.nginx.com/resources/admin-guide/nginx-https-upstreams/ 配置下吧

    试试 

    proxy_ssl_verify   off
    ######

    证书放nginx上 不用放后端服务器

    ######

    实体服务器应该不用配置,ssl证书需要配置在nginx上,参考 http://www.ahlinux.com/tomcat/21139.html配置: 

    nginx
    
    server {
            listen 443;
            server_name ssl.geeksy.pro;
    
    #       root html;
    #       index index.html index.htm;
    
            ssl on;
            ssl_certificate /home/song/nginxSSL/nginx.crt;
            ssl_certificate_key /home/song/nginxSSL/nginx.key;
    
            ssl_session_timeout 5m;
    
            ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
            ssl_prefer_server_ciphers on;
    
            location / {
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-Forwarded-Proto https;
                    proxy_redirect off;
                    proxy_connect_timeout 240;
                    proxy_send_timeout 240;
                    proxy_read_timeout 240;
                     # note, there is not SSL here!plain HTTP is used
                    proxy_pass http://127.0.0.1:8080;
            }
    }
    
    tomcat
    
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="443"
                   proxyPort="443"  />
    
             <Valve className="org.apache.catalina.valves.RemoteIpValve"
                    remoteIpHeader="x-forwarded-for" 
    
    
    


    个人理解:ssl防止中间有人篡改传输的信息,所以浏览器与你出口的服务器之间是加密的,所以你的ssl需要放在你的nginx上来配置,而不能让信息再转发到另一个upstream上。能力有限,有错误的地方请斧正~

    ######

    证书是要配置在nginx上的

    ######

    引用来自“北风刮的不认真了”的评论

    实体服务器应该不用配置,ssl证书需要配置在nginx上,参考 http://www.ahlinux.com/tomcat/21139.html配置: 

    nginx
    
    server {
            listen 443;
            server_name ssl.geeksy.pro;
    
    #       root html;
    #       index index.html index.htm;
    
            ssl on;
            ssl_certificate /home/song/nginxSSL/nginx.crt;
            ssl_certificate_key /home/song/nginxSSL/nginx.key;
    
            ssl_session_timeout 5m;
    
            ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
            ssl_prefer_server_ciphers on;
    
            location / {
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-Forwarded-Proto https;
                    proxy_redirect off;
                    proxy_connect_timeout 240;
                    proxy_send_timeout 240;
                    proxy_read_timeout 240;
                     # note, there is not SSL here!plain HTTP is used
                    proxy_pass http://127.0.0.1:8080;
            }
    }
    
    tomcat
    
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="443"
                   proxyPort="443"  />
    
             <Valve className="org.apache.catalina.valves.RemoteIpValve"
                    remoteIpHeader="x-forwarded-for" 
    
    
    


    个人理解:ssl防止中间有人篡改传输的信息,所以浏览器与你出口的服务器之间是加密的,所以你的ssl需要放在你的nginx上来配置,而不能让信息再转发到另一个upstream上。能力有限,有错误的地方请斧正~

    非常感谢各位,我问题解决了,把ssl证书配置在前端,然后其他还是一样,转发给后端服务器,就成功实现了

    ######抱歉我刚使用这个论坛,之后有积分了一定投######感觉哪个好就投个票,给点积极性,哈哈
    2020-06-01 09:50:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
CDN助力企业网站进入HTTPS时代 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载