nginx在Windows下反向代理cloudflare workers的配置文件粗略介紹


 

要點

1. 跟上游建立連接必須發送SNI,因為任播節點必須通過SNI來判斷你要訪問什么,也就是

proxy_ssl_server_name on;

2. 貌似要指定一個用來解析上游名稱的DNS服務器,也就是

resolver 8.8.8.8 8.8.4.4 valid=300s;

3.假如你跟我一樣Uri的Path部分是另一個Uri的話,上游收到的路徑會少一個正斜杠,也就是

https://a.com
#變成
https:/acom

 

極簡的主配置文件

events {
    
}


http {
   
    
    # HTTPS server
    #
    server {
        #服務器偵聽的端口
        listen 443 ssl http2;
        
        #證書和私鑰
        ssl_certificate      cert.pem;
        ssl_certificate_key  cert.key;

        #假如上游使用域名而不是地址需要用它設置DNS服務器(貌似)
        resolver 8.8.8.8 8.8.4.4 valid=300s;

        
        location / {
        
            proxy_set_header Connection ""; 
            proxy_http_version 1.1; 
          
            proxy_ssl_protocols TLSv1.2 TLSv1.3;
            #有些上游必須發送SNI否則無法建立連接
            proxy_ssl_server_name on;
            
            #類似於生成 https://www.a.com/https://www.b.com/a/b/index.html
            #但是變成Path的Uri會少一個反斜杠,在遠程端要加上
            #類似於變成了 /https:/www.b.com/a/b/index.html
            proxy_pass https://raspy-rain-5477.leikaifeng.workers.dev/$scheme://$host$request_uri;
            
        }

    }
}

 

 

Windows如何殺死nginx進程

使用命令

@taskkill /f /im nginx.exe

 

如何使用openssl簽CA與TLS證書

https://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate?page=1&tab=votes#tab-top

 

nginx反向代理模塊文檔

https://nginx.org/en/docs/http/ngx_http_proxy_module.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM