nginx代理服務(wù)器配置雙向證書驗證的方法
生成證書鏈
用腳本生成一個根證書, 一個中間證書(intermediate), 三個客戶端證書.
中間證書的域名為 localhost.
#!/bin/bash -x set -e for C in `echo root-ca intermediate`; do mkdir $C cd $C mkdir certs crl newcerts private cd .. echo 1000 > $C/serial touch $C/index.txt $C/index.txt.attr echo ' [ ca ] default_ca = CA_default [ CA_default ] dir = '$C' # Where everything is kept certs = $dir/certs # Where the issued certs are kept crl_dir = $dir/crl # Where the issued crl are kept database = $dir/index.txt # database index file. new_certs_dir = $dir/newcerts # default place for new certs. certificate = $dir/cacert.pem # The CA certificate serial = $dir/serial # The current serial number crl = $dir/crl.pem # The current CRL private_key = $dir/private/ca.key.pem # The private key RANDFILE = $dir/.rnd # private random number file nameopt = default_ca certopt = default_ca policy = policy_match default_days = 365 default_md = sha256 [ policy_match ] countryName = optional stateOrProvinceName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional [req] req_extensions = v3_req distinguished_name = req_distinguished_name [req_distinguished_name] [v3_req] basicConstraints = CA:TRUE ' > $C/openssl.conf done openssl genrsa -out root-ca/private/ca.key 2048 openssl req -config root-ca/openssl.conf -new -x509 -days 3650 -key root-ca/private/ca.key -sha256 -extensions v3_req -out root-ca/certs/ca.crt -subj '/CN=Root-ca' openssl genrsa -out intermediate/private/intermediate.key 2048 openssl req -config intermediate/openssl.conf -sha256 -new -key intermediate/private/intermediate.key -out intermediate/certs/intermediate.csr -subj '/CN=localhost.' openssl ca -batch -config root-ca/openssl.conf -keyfile root-ca/private/ca.key -cert root-ca/certs/ca.crt -extensions v3_req -notext -md sha256 -in intermediate/certs/intermediate.csr -out intermediate/certs/intermediate.crt mkdir out for I in `seq 1 3` ; do openssl req -new -keyout out/$I.key -out out/$I.request -days 365 -nodes -subj "/CN=$I.example.com" -newkey rsa:2048 openssl ca -batch -config root-ca/openssl.conf -keyfile intermediate/private/intermediate.key -cert intermediate/certs/intermediate.crt -out out/$I.crt -infiles out/$I.request done
服務(wù)器
nginx 配置
worker_processes 1;
events {
worker_connections 1024;
}
stream{
upstream backend{
server 127.0.0.1:8080;
}
server {
listen 8888 ssl;
proxy_pass backend;
ssl_certificate intermediate.crt;
ssl_certificate_key intermediate.key;
ssl_verify_depth 2;
ssl_client_certificate root.crt;
ssl_verify_client optional_no_ca;
}
}
客戶端
curl \ -I \ -vv \ -x https://localhost:8888/ \ --proxy-cert client1.crt \ --proxy-key client1.key \ --proxy-cacert ca.crt \ https://www.baidu.com/
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
- docker完整配置nginx+php+mysql的方法步驟
- Nginx跨域設(shè)置Access-Control-Allow-Origin無效的解決辦法
- nginx上部署react項目的實例方法
- 借用nginx.vim工具進行語法高亮和格式化配置nginx.conf文件
- nginx配置教程之a(chǎn)dd_header的坑詳解
- Nginx代理時header頭中帶"_"信息丟失問題的解決
- shell腳本之nginx自動化腳本
- Docker創(chuàng)建一個Nginx服務(wù)器的方法步驟
- 淺談docker運行nginx為什么要使用daemon off
- nginx proxy_cache批量清除緩存的腳本介紹
相關(guān)文章
詳解Nginx實戰(zhàn)之讓用戶通過用戶名密碼認證訪問web站點
這篇文章主要介紹了詳解Nginx實戰(zhàn)之讓用戶通過用戶名密碼認證訪問web站點,有興趣的可以了解一下。2016-11-11
Nginx配置的rewrite編寫時last與break的區(qū)別分析
這篇文章主要介紹了Nginx配置的rewrite編寫時last與break的區(qū)別分析,簡單來說使用last會對server標簽重新發(fā)起請求,而break就直接使用當前的location中的數(shù)據(jù)源來訪問,需要的朋友可以參考下2016-01-01
nginx如何根據(jù)報文里字段轉(zhuǎn)發(fā)至不同地址
要在 Nginx 中根據(jù) POST 請求的 JSON 負載中的 id 字段的值進行轉(zhuǎn)發(fā),你可以使用 Nginx 的 ngx_http_lua_module 模塊,這個模塊允許你在 Nginx 配置中使用 Lua 腳本,本文介紹nginx如何根據(jù)報文里字段轉(zhuǎn)發(fā)至不同地址,感興趣的朋友一起看看吧2024-12-12
Nginx實現(xiàn)動態(tài)內(nèi)容緩存的示例代碼
在Nginx中實現(xiàn)動態(tài)內(nèi)容的緩存可以顯著提高性能,減少后端服務(wù)器的負載,本文就來介紹一下Nginx動態(tài)內(nèi)容緩存實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2024-11-11
詳解Nginx的超時keeplive_timeout配置步驟
Nginx 處理的每個請求均有相應(yīng)的超時設(shè)置,本文主要介紹了Nginx的超時keeplive_timeout配置步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05

