nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示:
xxx.crt; #(证书公钥)
xxx.key; #(证书私钥)
把这两个文件放到nginx的conf文件夹下
打开nginx配置文件,添加配置段:
nginx.conf全部内容如下:
user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream tomcat8080_api {
server 127.0.0.1:8080 weight=1;
}
server {
listen 80;
server_name huituanquan.com;
#http转https(前提是已经配置nginx ssl证书)
rewrite ^(.*)$ https://$host$1 permanent;
}
# HTTPS
server {
listen 443;
server_name huituanquan.com; #网站域名
ssl on;
ssl_certificate huituanquan.com-ca-bundle.crt; #(证书公钥)
ssl_certificate_key huituanquan.com.key; #(证书私钥)
ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers HIGH:!aNULL:!MD5;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://tomcat8080_api;
proxy_redirect default;
#设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
最后重启nginx即可
/alidata/server/nginx/sbin/nginx -s reload
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2388.html