首页 > 代码库 > linux 下nginx 集群CAS单点登录实现
linux 下nginx 集群CAS单点登录实现
1.单点登录服务器CAS应用配置于tomcat下。
1)key生成:
keytool -genkey -alias mycas -keyalg RSA -keysize 2048 -keystore /mnt/disk1/keys/mycas.keystore
keytool -export -file /mnt/disk1/keys/mycas.crt -alias mycas -keystore /mnt/disk1/keys/mycas.keystore
2)CAS发布tomcat中server.xml中配置
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/mnt/disk1/keys/mycas.keystore" keystorePass="123456" />
3)如果不使用集群,通过java端通过CAS client直接连接此CAS服务器,则需要在jdk中导入相应的证书文件:
keytool -delete -alias mycas -keystore \usr\local\jdk\jre\lib\security\cacerts //删除证书
keytool -import -keystore \usr\local\jdk\jre\lib\security\cacerts -file /mnt/disk1/keys/mycas.crt -alias myca //导入证书
2.nginx负载多个tomcat
1)nginx ssl证书生成
cd /mnt/disk1/nginxkeys 进入证书存储文件夹
openssl genrsa -des3 -out server.key 1024 创建服务器私钥
openssl req -new -key server.key -out server.csr 创建证书签名请求(CSR)
[
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:BJ
Locality Name (eg, city) [Newbury]:BJ
Organization Name (eg, company) [My Company Ltd]:test
Organizational Unit Name (eg, section) []:test
Common Name (eg, your name or your server‘s hostname) []:cas112.test.com(在使用casclient时候必须在这里填入域名,否则报错)
Email Address []:l@test.com
]
cp server.key server.key.org 在加载SSL支持的Nginx并使用上述私钥时除去必须的口令
openssl rsa -in server.key.org -out server.key 在加载SSL支持的Nginx并使用上述私钥时除去必须的口令
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 使用上述私钥导出CSR,CRT签名证书:
2)nginx https接口配置
upstream cas_server_ssl { #ip_hash; server localhost:8443; } server { listen 443; server_name localhost; ssl on; ssl_certificate /mnt/disk1/nginx_keys/server.crt; ssl_certificate_key /mnt/disk1/nginx_keys/server.key; location / { root html; index index.html index.htm; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass https://cas_server_ssl; } }
3.客户端配置
同跟不使用nginx集群配置类似,将server.crt导入靠客户端需要使用机器。
keytool -delete -alias mycas -keystore \usr\local\jdk\jre\lib\security\cacerts //删除证书
keytool -import -keystore \usr\local\jdk\jre\lib\security\cacerts -file /mnt/disk1/keys/server.crt -alias nginxca //导入证书
linux 下nginx 集群CAS单点登录实现