Nginx配置http跳转https, php的支持

http跳转https

首先要申请好ssl证书,可使用免费的或购买的证书,有想了解获取免费的ssl证书的请留言,找时间发布篇关于Let's Encrypt的免费证书申请的文章。

server {
    listen 80;
    server_name www.example.com example.com;
    rewrite ^(.*) https://$server_name$1 permanent;
    #rewrite ^(.*) https://$host$1 permanent;
    #rewrite ^(.*) https://example.com$1 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会有如下效果,即以http://www.example.com或http://example.com访问会跳转至https://www.example.com地址;

2、使用$host则是这样的,以http://www.example.com访问时跳转至https://www.example.com,以http://example.com访问跳转至https://example.com;

3、直接使用确定的域名https://example.com,那么在访问http://example.com或者http://www.example.com时都直接跳转到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; 
    } 
展开阅读全文

页面更新:2024-03-08

标签:前提   证书   规则   效果   留言   地址   域名   时间   数码   文章

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top