NGINX配置HTTPS

nginx配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
upstream tomcat {
server 127.0.0.1:8080 fail_timeout=0;
}

# HTTPS server
server {
listen 443 ssl;
server_name codedog.link;

ssl_certificate server.crt;
ssl_certificate_key server.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;


location / {
root html;
index index.html index.htm;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
# note, there is not SSL here! plain HTTP is used
proxy_pass http://tomcat;
}
}

nginx 80端口 转443端口

1
2
3
4
5
6
7
8
9
server {

listen 80;

server_name codedog.link;

return 301 https://$server_name$request_uri;

}