二、Nginx 配置 https

ajiang02發表於2020-08-01

原因

有些瀏覽器對網站的安全提出了嚴格的要求,如果想要訪問電腦的相機的,就需要使你的網站使用 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 協議》,轉載必須註明作者和本文連結

相關文章