zoukankan      html  css  js  c++  java
  • Nginx采用https加密访问后出现的问题

    线上的一个网站运行了一段时间,应领导要求,将其访问方式更改为https加密方式。
    更改为https后,网站访问正常,但网站注册功能不能正常使用了!

    经过排查,是nginx配置里结合php部分漏洞了一个参数(fastcgi_param  HTTPS )导致,添加上这个参数后,问题迎刃而解!
    nginx支持https的配置时,需要在php区域配置中添加FastCGI服务,否则https不支持php文件。

    location ~ .php$ {
    root /var/www/vhosts/fff/main;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_read_timeout 30;
    fastcgi_index fff.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    #include fastcgi_params;
    include fastcgi.conf;
    fastcgi_param HTTPS on;                        【或者fastcgi_param HTTPS     $https if_not_empty; 】
    }
    }

    *******************************************************************************************

    如何开启 Nginx 的 SSL 或者 HTTPS呢?

    大家有没有试过使用HTTPS登陆 phpmyadmin 的时候会自动返回“The plain HTTP request was sent to HTTPS port”?

    这是个 fastcgi 的配置问题!

    解决方法:

    location ~ .*.(php|php5)?$
    {
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_param HTTPS     $https if_not_empty;
    fastcgi_index index.php;
    include fcgi.conf;
    }

    解释:

    很多人认为使用 fastcgi_param HTTPS on;,这样是没错啦,不过强迫使用这个参数,可能不太有效!

    最好的答案是上面的配置(参考下面 nginx 官方的链接)

    fastcgi_param HTTPS $https if_not_empty;

    有 https 协议时才自动使用 https on,否则忽略这个参数。

    内嵌的变量:

    $https – 如果链接是 SSL 就返回 “ON”,否则返回空字符串。

    if_not_empty; – 当参数有值时才传递到服务器

    注意:这个 if_not_empty 额外参数只适合 Nginx 1.1.11 之后的版本

  • 相关阅读:
    C 语言
    How does Chrome Extension crx Downloader work? ——— From crxdown.com
    做作业时看到的 Demo
    IDEA 插件收集
    [E] Shiro 官方文档阅读笔记 The Reading Notes of Shiro's Offical Docs
    烦人的 Python 依赖
    机器学习之路--Numpy
    机器学习之路--朴素贝叶斯
    机器学习之路--决策树
    机器学习之路--KNN算法
  • 原文地址:https://www.cnblogs.com/kevingrace/p/5681023.html
Copyright © 2011-2022 走看看