首先找到nginx.conf文件;
方式1,http和https同时监听,自动跳转https;
server {
listen 80;
listen 443 ssl;
server_name www.xxx.com xxx.com; #填写绑定证书的域名
#ssl on;
ssl_certificate 1_www.xxx.com_bundle.crt; #证书在conf文件同级;
ssl_certificate_key 2_www.xxx.com.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:8081; #转发到本机项目端口
}
}
方式2,http自动跳转https;
server {
listen 80;
server_name api.xxx.com;
#rewrite ^(.*) https://$server_name$1 permanent; #自动跳转到https
}
server {
listen 443 ssl;
server_name api.xxx.com; #填写绑定证书的域名
#ssl on; #新版本不需要配置,否则有警告
ssl_certificate 1_xx.com_bundle.crt;
ssl_certificate_key 2_xx.com.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_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:9000;
}
}
方式3,http,https同时可访问;
server {
listen 80;
server_name api.xxx.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 443 ssl;
server_name api.xxx.com; #填写绑定证书的域名
#ssl on;
ssl_certificate 1_xxx.com_bundle.crt;
ssl_certificate_key 2_xxx.com.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_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}