nginx Http跳转到Https

发布时间:2020-10-14 14:19:52 阅读:1046次

给网站配置https证书

nginx配置文件监听80和443,

当访问80端口的时候自动跳转到443

server {                                                                                                                                                    
    listen 443;
    ssl                 on; 
    ssl_certificate     www.test.cn.crt;  #证书
    ssl_certificate_key www.test.cn.key; #私钥
    server_name     www.test.cn;
    root   "/var/www/html/test/public";
    access_log /usr/local/nginx/logs/www.test.com.log main;
    error_log /usr/local/nginx/logs/www.test.com.error.log;
    location / {
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
        }   
    }   
    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include fastcgi_params;
    }   
    location ^~ /v/{
        proxy_pass http://10.10.0.6:8096/;
    }   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)?$ {
        expires    1d; 
        access_log off;
        }
}
server {
    listen       80;
    server_name  www.test.cn;
    root   "/var/www/html/test/public";
    rewrite ^(.*)$ https://$host$1 permanent;
}

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:nginx Http跳转到Https 出自老鄢博客 | 欢迎分享