二、Nginx 配置 https

原因

有些浏览器对网站的安全提出了严格的要求,如果想要访问电脑的相机的,就需要使你的网站使用 SSL/HTTPS。

下载证书

本地调试,直接使用工具 mkcert下载证书。
mkcert 在不同平台的安装方法:github.com/FiloSottile/mkcert
Windows 也可以在这里下载:www.yx12345.com/pcpd/7140/170.html
生成证书后,放到你的项目根目录去。

配置 nginx.conf

将生成的两个 pem 文件路径配置到 ssl_certificate ssl_certificate_key

# HTTPS server

    server {
        listen       443 ssl;
        server_name  www.webcam.com;

        ssl_certificate      F:/webcamjs-master/www.webcam.com.pem;
        ssl_certificate_key  F:/webcamjs-master/www.webcam.com-key.pem;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   F:/webcamjs-master;
            index  index.php index.htm index.html;
            if (!-e $request_filename) {
                    rewrite  ^(.*)$  /index.php?s=/$1  last;
                    break;
            }
            # 解决:静态文件响应POST请求,返回“HTTP/1.1 405 Method not allowed”
            error_page 405 =200 https://$host$request_uri;
        }

        location ~ \.php$ {
                root           F:/webcamjs-master;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_param PATH_INFO $fastcgi_path_info;
                include        fastcgi_params;
        }
    }
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!