Nginx配置ssl证书
一.检查nginx是否安装SSL的依赖
1.输入命令查询版本信息
windows版本
nginx.exe -V
linux版本
nginx -V
输出结果,检查with-mail_ssl_module是否安装,如果已安装跳过第二步
nginx version: nginx/1.19.4
built by cl 16.00.40219.01 for 80x86
built with OpenSSL 1.1.1h 22 Sep 2020
TLS SNI support enabled
configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre-8.44 --with-zlib=objs.msvc8/lib/zlib-1.2.11 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.1.1h --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module
2.安装依赖with-mail_ssl_module
注意:安装依赖需要重装nginx,在重装之前需要备份已安装nginx的配置
在nginx解压的目录下输入命令
./configure --with-http_ssl_module
执行make命令进行编译
make
执行make install命令进行覆盖
make install
将备份好的nginx配置还原即可
二.SSL配置
http{
server{
listen 443;
server_name websocketServer;
# ssl配置
ssl on;
ssl_certificate /keystore/server.csr;
ssl_certificate_key /keystore/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
#代理地址
proxy_pass http://127.0.0.1:8080;
}
}
}