nginx配置反向代理https


以windows為例

  1. 下載安裝openssl

http://slproweb.com/download/Win64OpenSSL-1_1_1L.exe
如果失效可以去這里找對應的版本下載https://slproweb.com/products/Win32OpenSSL.html

  1. 生成證書
創建私鑰, 輸入密碼
openssl genrsa -des3 -out test.key 1024 

創建csr證書
openssl req -new -key test.key -out test.csr

復制test.key並重命名為test.copy.key, 
copy test.key test.copy.key

去除密碼, 不去除nginx每次啟動都得輸密碼, 根據提示輸入地區 單位 個人郵箱信息等
openssl rsa -in test.copy.key -out test.key

生成crt證書
openssl x509 -req -days 365 -in test.csr -signkey test.key -out test.crt

證書有效期為1年, 到期后需要重新生成

  1. 安裝nginx

http://nginx.org/download/nginx-1.20.1.zip

  1. 配置nginx
server {

	#端口
	listen       443 ssl;
	#多個server的name不能重名 改成自己系統的
	server_name  demo;      
	client_max_body_size 200m;
	
	ssl_certificate      C:/nginx-1.19.6/ssl/test.crt;  # 這個是證書的crt文件所在目錄
    ssl_certificate_key  C:/nginx-1.19.6/ssl/test.key; # 這個是證書key文件所在目錄
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
 
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;	
	
	
	location /test/ {
		proxy_pass https://fxpc.mem.gov.cn/;        
        proxy_redirect http:// $scheme://; #做https跳轉
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;		
		#proxy_set_header Host      $host;
        #proxy_set_header X-Real-IP $remote_addr;
		
	}
	
   
}


免責聲明!

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



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