利用nginx实现https访问,同时添加秘钥和和防止跨站访问,这里我只修改了一些默认的参数,
vi nginx.conf
server {
listen 443 default_server ssl; # 打开https的端口号,启用https的443端口
server_name www.a.com; # 服务器的虚拟web主机名,是绑定证书的域名
ssl on; # 打开https的服务
ssl_certificate ../cert/a.com.crt; # https的证书文件位置,默认是从web网页的根目录查找的
ssl_certificate_key ../cert/a.com.key; # https的秘钥文件位置,默认是从web网页的根目录查找的
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
}
}
# “add_header Access-Control-Allow-Origin *” 中的*代表任何网站都可以跳转到这个根目录,如果将*设置成www.a.com则只允许www.a.com访问该站点的根目录。
想了解更多请查看https://blog.csdn.net/qq_27008807/article/details/78877877,我也是查看他的