nginx代理服務(wù)器配置雙向證書驗(yàn)證的方法
生成證書鏈
用腳本生成一個(gè)根證書, 一個(gè)中間證書(intermediate), 三個(gè)客戶端證書.
中間證書的域名為 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é)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- docker完整配置nginx+php+mysql的方法步驟
- Nginx跨域設(shè)置Access-Control-Allow-Origin無(wú)效的解決辦法
- nginx上部署react項(xiàng)目的實(shí)例方法
- 借用nginx.vim工具進(jìn)行語(yǔ)法高亮和格式化配置nginx.conf文件
- nginx配置教程之a(chǎn)dd_header的坑詳解
- Nginx代理時(shí)header頭中帶"_"信息丟失問(wèn)題的解決
- shell腳本之nginx自動(dòng)化腳本
- Docker創(chuàng)建一個(gè)Nginx服務(wù)器的方法步驟
- 淺談docker運(yùn)行nginx為什么要使用daemon off
- nginx proxy_cache批量清除緩存的腳本介紹
相關(guān)文章
nginx實(shí)現(xiàn)請(qǐng)求轉(zhuǎn)發(fā)
本文給大家分享的是使用nginx實(shí)現(xiàn)代理(請(qǐng)求轉(zhuǎn)發(fā))的教程及簡(jiǎn)單示例,非常實(shí)用,有需要的小伙伴可以參考下2017-07-07
詳解Nginx實(shí)戰(zhàn)之讓用戶通過(guò)用戶名密碼認(rèn)證訪問(wèn)web站點(diǎn)
這篇文章主要介紹了詳解Nginx實(shí)戰(zhàn)之讓用戶通過(guò)用戶名密碼認(rèn)證訪問(wèn)web站點(diǎn),有興趣的可以了解一下。2016-11-11
為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法
為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法,需要的朋友可以參考下。2010-12-12
Nginx配置的rewrite編寫時(shí)last與break的區(qū)別分析
這篇文章主要介紹了Nginx配置的rewrite編寫時(shí)last與break的區(qū)別分析,簡(jiǎn)單來(lái)說(shuō)使用last會(huì)對(duì)server標(biāo)簽重新發(fā)起請(qǐng)求,而break就直接使用當(dāng)前的location中的數(shù)據(jù)源來(lái)訪問(wèn),需要的朋友可以參考下2016-01-01
nginx如何根據(jù)報(bào)文里字段轉(zhuǎn)發(fā)至不同地址
要在 Nginx 中根據(jù) POST 請(qǐng)求的 JSON 負(fù)載中的 id 字段的值進(jìn)行轉(zhuǎn)發(fā),你可以使用 Nginx 的 ngx_http_lua_module 模塊,這個(gè)模塊允許你在 Nginx 配置中使用 Lua 腳本,本文介紹nginx如何根據(jù)報(bào)文里字段轉(zhuǎn)發(fā)至不同地址,感興趣的朋友一起看看吧2024-12-12
Nginx多ip部署多站點(diǎn)的實(shí)現(xiàn)步驟
使用Nginx在具有多個(gè)IP地址的服務(wù)器上部署多個(gè)站點(diǎn),從而實(shí)現(xiàn)高效、安全的網(wǎng)站托管,本文主要介紹了Nginx多ip部署多站點(diǎn)的實(shí)現(xiàn)步驟,感興趣的可以了解一下2024-01-01
Nginx實(shí)現(xiàn)動(dòng)態(tài)內(nèi)容緩存的示例代碼
在Nginx中實(shí)現(xiàn)動(dòng)態(tài)內(nèi)容的緩存可以顯著提高性能,減少后端服務(wù)器的負(fù)載,本文就來(lái)介紹一下Nginx動(dòng)態(tài)內(nèi)容緩存實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-11-11
詳解Nginx的超時(shí)keeplive_timeout配置步驟
Nginx 處理的每個(gè)請(qǐng)求均有相應(yīng)的超時(shí)設(shè)置,本文主要介紹了Nginx的超時(shí)keeplive_timeout配置步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05

