2016-11-26 122 views
2

我有 - 轉到服務器作爲一名傾聽HTTPHTTPSNginx配置爲處理傳入的http + https請求。證書的順序。 使用單獨的服務器在https協議上查詢結果時可以完美運行。然而,當我使用代理nginx的 HTTPS沒有得到來自服務器的響應和服務器轉到Golang +的nginx + HTTPS

的「http:TLS握手錯誤從127.0.0.1:54037:TLS:第一條記錄 做不像TLS握手

可能是什麼問題

客戶轉到:

package main 

import (
    "net/http" 
    "log" 

) 

func HelloSSLServer(w http.ResponseWriter, req *http.Request) { 
    w.Header().Set("Content-Type", "text/plain") 
    w.Write([]byte("This is an example server.\n")) 
    // fmt.Fprintf(w, "This is an example server.\n") 
    // io.WriteString(w, "This is an example server.\n") 
} 

func main() { 
    http.HandleFunc("/", HelloSSLServer) 
    go http.ListenAndServe("192.168.1.2:80", nil) 
    err := http.ListenAndServeTLS("localhost:9007", "/etc/letsencrypt/live/somedomain/fullchain.pem", "/etc/letsencrypt/live/somedomain/privkey.pem", nil) 

    if err != nil { 
     log.Fatal("ListenAndServe: ", err) 
    } 



} 

Nginx的配置:

server { 
    listen  192.168.1.2:80; 
    server_name somedomain; 
    rewrite^https://$host$request_uri? permanent;  
} 
server { 
    listen  192.168.1.2:443 ssl; 
    server_name somedomain; 
    access_log /var/log/nginx/dom_access.log; 
    error_log  /var/log/nginx/dom_error.log; 
    ssl_certificate  /stuff/ssl/domain.cert; 
    ssl_certificate_key /stuff/ssl/private.cert; 
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers   ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 


    location/
    { 
     proxy_pass http://localhost:9007; 
#  proxy_redirect http://localhost:1500 http://site1; 
     proxy_cookie_domain localhost somedomain; 
     proxy_buffering off; 

     proxy_http_version 1.1; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header Client-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $remote_addr; 
    } 
} 

回答

4

使用https與proxy_pass

location/
{ 
    proxy_pass https://localhost:9007; 
    ... 
} 
+1

Ofc。疲憊的眼睛從工作。謝謝。 – Spouk

0

nginx的config文件應該喜歡這個

server { 
     listen 443 ssl http2; 
     listen 80; 
     server_name www.mojotv.cn; 
     ssl_certificate  /home/go/src/my_go_web/ssl/**.pem; 
     ssl_certificate_key /home/go/src/my_go_web/ssl/**.key; 
     ssl_session_timeout 5m; 
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
     ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL; 
     ssl_prefer_server_ciphers on; 
     location /(css|js|fonts|img)/ { 
      access_log off; 
      expires 1d; 
      root "/home/go/src/my_go_web/static"; 
      try_files $uri @backend; 
     } 
     location/{ 
      try_files /_not_exists_ @backend; 
     } 
     location @backend { 
      proxy_set_header X-Forwarded-For $remote_addr; 
      proxy_set_header Host $http_host; 
      proxy_pass http://127.0.0.1:********; 
     } 
     access_log /home/wwwroot/www.mojotv.cn.log;## nginx log path 
} 

the golang web app with http2 ssl feature shiped with nginx

0

我得到對於沒有額外配置的更基本的Go服務器而言,類似的錯誤消息給OP。

TLS:第一條記錄看起來並不像一個TLS握手

我的臨時補丁只是要確保測試的網址包括「https://開頭」,並在URL的端口號。

沒有工作 - ip地址

沒有工作 - https://ipaddress

工作 - https://ipaddress:8081

它會爲測試做,直到一個更高級的設置。只需發佈此信息可幫助其他人解決問題。