nginx配置https的雙向認(rèn)證方式
更新時(shí)間:2024年11月19日 09:35:26 作者:CheerTan
文章主要介紹了如何配置Nginx雙向認(rèn)證的詳細(xì)步驟,包括生成證書、配置Nginx等,并提供了個(gè)人經(jīng)驗(yàn)供參考
注意事項(xiàng)
配置雙向認(rèn)證,這里的common name需要都配置成不同
nginx 配置 https的雙向認(rèn)證
準(zhǔn)備工作
linux環(huán)境安裝openssl
生成證書步驟
1.新建一個(gè)文件夾
mkdir /root/keys
2.生成CA私鑰 ca.key
openssl genrsa -out ca.key 4096
3.生成ca的數(shù)字證書 ca.crt
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: 填入組織名稱等信息
4.生成server端的私鑰
openssl genrsa -out server.key 4096
5.生成 server 端數(shù)字證書請求
openssl req -new -key server.key -out server.csr Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:Shanghai Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]:Sidien Test Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:192.168.0.162 Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: 輸入相關(guān)信息和密碼
6.用 CA 私鑰簽發(fā) server 的數(shù)字證書
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 3650
7. 生成客戶端私鑰
openssl genrsa -out client.key 4096
8. 生成客戶端數(shù)字請求證書
openssl req -new -key client.key -out client.csr Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: 輸入相關(guān)信息和密碼
9.用CA私鑰簽發(fā)數(shù)字證書:client.crt
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 3650
10.生成windows安裝證書程序
openssl pkcs12 -export -inkey client.key -in client.crt -out client.pfx
將client.pfx拷貝到作為客戶端的機(jī)器上,安裝證書,輸入生成時(shí)的密碼
11.配置nginx
ssl_certificate /etc/pki/ca_linvo/server/server.crt; #server公鑰路徑 ssl_certificate_key /etc/pki/ca_linvo/server/server.key; #server私鑰路徑 ssl_client_certificate /etc/pki/ca_linvo/root/ca.crt; #根級證書公鑰路徑,用于驗(yàn)證各個(gè)二級client ssl_verify_client on; 開啟雙向認(rèn)證
認(rèn)證成功
curl --cert ./client.crt --key ./client.key https://url -k -v


開啟gzip跟緩存
gzip on;
gzip_min_length 256;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 3;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
#這里設(shè)置需要壓縮的格式
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
location / {
root /root/www/web;
index index.html;
autoindex on;
if ($request_filename ~ .*.(js|css)$)
{
expires 7d;
}
}
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- https如何通過nginx完成雙向認(rèn)證轉(zhuǎn)發(fā)
- Nginx配置Https安全認(rèn)證的實(shí)現(xiàn)
- Nginx+SSL實(shí)現(xiàn)雙向認(rèn)證的示例代碼
- 詳解Nginx SSL快速雙向認(rèn)證配置(腳本)
- nginx環(huán)境下配置ssl加密(單雙向認(rèn)證、部分https)
- Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例
- 使用Lua編寫Nginx服務(wù)器的認(rèn)證模塊的方法
- Nginx用戶認(rèn)證配置方法詳解(域名/目錄)
- 使用LDAP實(shí)現(xiàn)Nginx用戶認(rèn)證的示例
相關(guān)文章
Nginx + Tomcat實(shí)現(xiàn)請求動態(tài)數(shù)據(jù)和請求靜態(tài)資源的分離詳解
這篇文章主要給大家介紹了關(guān)于Nginx + Tomcat實(shí)現(xiàn)請求動態(tài)數(shù)據(jù)和請求靜態(tài)資源的分離的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07
Nginx proxy_set_header參數(shù)設(shè)置
本文主要介紹了Nginx proxy_set_header參數(shù)設(shè)置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09
nginx加php-fpm出現(xiàn)502 bad gateway錯(cuò)誤的5種解決方法
這篇文章主要介紹了nginx加php-fpm環(huán)境中出現(xiàn)502 bad gateway錯(cuò)誤的5種解決方法,總結(jié)歸納服務(wù)器出現(xiàn)502錯(cuò)誤的原因多數(shù)為連接過多和腳本超時(shí),本文總結(jié)了5種解決方法,需要的朋友可以參考下2014-05-05
權(quán)限問題導(dǎo)致Nginx 403 Forbidden錯(cuò)誤的解決方法
這篇文章主要介紹了權(quán)限問題導(dǎo)致Nginx 403 Forbidden錯(cuò)誤的解決方法,本文中導(dǎo)致 403 Forbidden錯(cuò)誤的原因是配置文件中沒有指明一個(gè)用戶,需要的朋友可以參考下2014-08-08

