为了网站的安全,以及一些开发需要,例如小程序就规定api服务器必须安装ssl证书,支持https
这个时候我们可以购买相关证书,购买完证书之后配置如下
注意的是 location 配置视业务而定,不是配置https的关键点
server {
listen 443 ;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/1_www.xxx.cn_bundle.crt;#购买证书后下载的crt
ssl_certificate_key /etc/nginx/2_www.xxx.cn.key;#购买证书后下载的key
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
if ($server_port = 80) {
rewrite ^(.*)$ https://$host$1 permanent;#80端口进来的重定向到443端口 如果http跟https一起使用可注释这个
}
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ .php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
完成!