gpt4 book ai didi

nginx - 戈兰 + nginx + https

转载 作者:IT王子 更新时间:2023-10-29 00:58:39 27 4
gpt4 key购买 nike

我有 - Go 作为监听器 httphttps 到服务器。 Nginx 配置为处理传入的 http + https 请求。证件有序。使用单独的服务器可以完美地运行在 https 协议(protocol)上对它们的查询结果。但是,当我使用代理 nginx https 时,服务器没有收到响应,服务器 Go

"http: TLS handshake error from 127.0.0.1:54037: tls: first record does not look like a TLS handshake

可能是什么问题?

客户端Go:

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;
}
}

最佳答案

使用 https 和 proxy_pass

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

关于nginx - 戈兰 + nginx + https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40817027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com