相比于http,https进行加密,在安全性上好非常多,这里就nginx下https配置进行介绍。
平台信息:
os: centos 7 64位
nginx版本:
./usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --user=nginx --group=nginx --http-scgi-temp-path=/var/temp/nginx/scgi
1、配置https模块
在上面的nginx -V可以看到我这里的nginx我已经增加了ssl的模块。
如果没有的话,重新make下nginx,增加下 --with-http_ssl_module模块。
进入原来下载nginx的安装目录,注意不是目前已经安装了的/usr/local/nginx目录。
重新配置nginx
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_stub_status_module \
--with-pcre \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--user=nginx \ --group=nginx \
--http-scgi-temp-path=/var/temp/nginx/scgi
我这里配置了比较多的模块,可以根据自己的要求进行选择,重点是要增加:with-http_ssl_module
重新生成文件,执行命令: make
#主要不要加上 & make install ,否则会重新进行安装。
在目录下已经重新生成了nginx文件,将新生成的nginx文件替换现有的nginx文件。
./usr/local/nginx/sbin/nginx -s stop
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp nginx /usr/local/nginx/sbin/nginx
./usr/local/nginx/sbin/nginx -s start
./usr/local/nginx/sbin/nginx -V
正常情况下已经增加with-http_ssl_module模块了。
2、生成ssl证书
这里可以到阿里云下去生成ssl证书,目前免费的可以申请20个证书。
相关的申请可按照阿里云的提示操作下即可。
正常15分钟左右就可以获取到生成的ssl证书。
3、nginx下server的配置
将第二步生成的ssl证书上传到nginx服务器上,这里创建了一个cert的证书目录
cd /usr/local/nginx
mkdir cert
将证书文件放到该目录下。
重新配置下server:
参考配置:
server {
listen 443 ssl;
server_name e-seal.****.cn;
#access_log error_log
error_log /var/log/nginx/error_eseal.log error;
access_log /var/log/nginx/access_eseal.log main;
ssl_certificate cert/****.pem;
ssl_certificate_key cert/****.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://172.16.109.115:8723;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
client_max_body_size 500m;
client_body_buffer_size 928k;
}
}
server {
listen 80;
server_name e-seal.jolma.cn;
rewrite ^(.*) https://$server_name$1 permanent;
}
这里需要注意强制重定下,需要考虑原来的toncat之类的是否做了ssl的配置,否则会出现问题。
尝试访问网站,如果没有报错就是已经配置正常。
如果有不清楚的欢迎留言问下,帮您看下什么问题。
如果觉得对您有用,欢迎转发、转载。
本文暂时没有评论,来添加一个吧(●'◡'●)