http跳转https
首先要申请好ssl证书,可使用免费的或购买的证书,有想了解获取免费的ssl证书的请留言,找时间发布篇关于Let’s Encrypt的免费证书申请的文章。
server { listen 80; server_name www.example.com example.com; rewrite ^(.*) permanent; #rewrite ^(.*) permanent; #rewrite ^(.*) permanent;}server { listen 443 ssl; server_name www.example example.com; root /home/www; ssl_certificate /etc/nginx/certs/server.crt; ssl_certificate_key /etc/nginx/certs/server.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;}
rewrite规则中
1、使用$server_name会有如下效果,即以或访问会跳转至 https ://www.example.com地址;
2、使用$host则是这样的,以访问时跳转至以访问跳转至 https ://example.com;
3、直接使用确定的域名,那么在访问或者时都直接跳转到 https ://example.com
php的支持
配置如下,前提是安装php时要启用php-fpm,即编译时要带–enable-fpm,并启动了php-fpm服务。
location ~* \.php$ { fastcgi_index index.php; root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }