假如配置的https://api.test.com
配置域名解析时,除了配置https的解析,一定要把http://api.test.com也配置上。这样http://api.test.com访问地址,强制跳转到https://api.test.com。
配置443时,一定要配置一下80端口,让其他强制跳转到443端上,不然就https没有办法解析到dns。可以在成功访问ssl端口后,再把把80端口的强制跳转取消掉
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name api.ishiwanapp.cn;
#charset koi8-r;
#access_log logs/host.access.log main;
rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
location / {
index index.html index.htm;
}
# location / {
# root html;
# index index.html index.htm;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 443 ssl;
server_name api.ishiwanapp.cn;
ssl_certificate /usr/local/nginx/nginx-1.14.2/conf/cert/8959612_api.ishiwanapp.cn.pem;
ssl_certificate_key /usr/local/nginx/nginx-1.14.2/conf/cert/8959612_api.ishiwanapp.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示使用的TLS协议的类型,您需要自行评估是否配置TLSv1.1协议。
ssl_prefer_server_ciphers on;
location / {
root html; #Web网站程序存放目录。
index index.html index.htm;
}
}
}
网友评论