nginx 代理服務(wù)器配置雙向證書(shū)驗(yàn)證的方法
生成證書(shū)鏈
用腳本生成一個(gè)根證書(shū), 一個(gè)中間證書(shū)(intermediate), 三個(gè)客戶端證書(shū).
腳本來(lái)源于(有修改)
https://stackoverflow.com/questions/26759550/how-to-create-own-self-signed-root-certificate-and-intermediate-ca-to-be-importe
中間證書(shū)的域名為 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/
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- CentOS 7.3配置Nginx虛擬主機(jī)的方法步驟
- Django uwsgi Nginx 的生產(chǎn)環(huán)境部署詳解
- PHP-FPM和Nginx的通信機(jī)制詳解
- 利用Nginx反向代理解決跨域問(wèn)題詳解
- shell腳本之nginx自動(dòng)化腳本
- Docker創(chuàng)建一個(gè)Nginx服務(wù)器的方法步驟
- 淺談docker運(yùn)行nginx為什么要使用daemon off
- Docker中運(yùn)行nginx并掛載本地目錄到鏡像中的方法
- 為docker中的nginx配置https的方法步驟
- nginx代理服務(wù)器配置雙向證書(shū)驗(yàn)證的方法
相關(guān)文章
nginx?某些url只能由特定ip訪問(wèn)的實(shí)現(xiàn)
在Nginx中針對(duì)某些URL只允許特定IP地址訪問(wèn),本文就來(lái)介紹一下如何實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程
負(fù)載均衡用于從“upstream”模塊定義的后端服務(wù)器列表中選取一臺(tái)服務(wù)器接受用戶的請(qǐng)求,下面這篇文章主要給大家介紹了關(guān)于使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08關(guān)于Nginx開(kāi)啟gzip的配置的問(wèn)題
這篇文章主要介紹了關(guān)于Nginx開(kāi)啟gzip的配置的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03