在我的 Rpi 上加载资源时出现 SSL 问题

Trouble with SSL when loading resources on my Rpi

我在 Raspbian 上使用 Asp.Net Core。

我正在使用 NGINX 作为我的网络服务器

我正在尝试加载资源并连接到我的网络 api 控制器

问题是我的 uri 正在从 http 更改为 https。

因为我想在网络上的其他地方浏览此站点,所以我能实现的目标非常有限。如果我在 Pi 本身上并使用 localhost 或 127.0.0.1 那么一切都加载正常。如果我使用 dhcp 地址访问它,它会失败。

之所以有效,是因为我使用的是 Open SSL,但仅限于本地级别。

这是我的 NGINX:

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
    listen               443;
    ssl                  on;
    ssl_certificate      /home/pi/web/localhost.crt;
    ssl_certificate_key  /home/pi/web/localhost.key;
    ssl_ciphers          HIGH:!aNULL:!MD5;


root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;






location /FindMotion/ {
        proxy_pass http://localhost:5000/;
        proxy_http_version 1.1;
        proxy_set_header Connection keep-alive;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host   $http_host;
        proxy_set_header X-Forwarded-Proto  http;
        proxy_set_header X-Forwarded-Path   /FindMotion;
}
}

这是我的 Javascript:

var timer;
function RenderImage() {
    try {

        $.ajax({
            url: "/Connection/ImageData",
            success: function(response) {
                var image = new Image();
                image.src = 'data:image/png;base64,' +response;
                document.body.appendChild(image);
                timer = setTimeout(function() { RenderImage(); }, 10000);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#divImage").html("ERROR: " + errorThrown);
                timer = setTimeout(function() { RenderImage(); }, 10000);
            }
        });
    } catch (err) {
        $("#divImage").html(err);
        timer = setTimeout(function() { RenderImage(); }, 10000);
    }
}

RenderImage();

这是我的控制器:

[ HttpGet ]
[ Route( "Connection/ImageData" ) ]
public string GetImageData()
{
    var img = new Bitmap( "20190521141101456.jpg" );

    using ( MemoryStream mStream = new MemoryStream() )
    {       
            img.Save( mStream, img.RawFormat );
            var bytes = mStream.ToArray();
            var data = Convert.ToBase64String( bytes );
            return data;
        }
    }
}

浏览控制台中的错误是: https://192.168.0.12/Connection/ImageData 404(未找到)

我认为这不能工作是因为 Open SSL 不够用吗?

如果是这样的话,我认为我必须获得一个 'proper' SSL 并且为此需要一个域名的想法是否正确?

如果是这样,我 sell/produce 每个产品都需要一个域名和静态地址?

我是完全错了还是对了?请问我有什么选择?这几天我试了很多东西都没用。

我非常需要建议。

谢谢

我认为这更有可能是 nginx 配置问题。 404 not found 表示 403 上没有任何内容。并不是说 TSL 版本或 SSL 版本不适合您。您可能会从 nginx 收到 400(错误请求)或 495(SSL 错误)。

像这样尝试。对此我不确定。但是我从来没有见过在同一个块中同时配置 http 和 https 。现在我离系统管理员还很远,但我自己的服务器设置更像这样。我还在其中放了一行 ssl_protocols 来基本上指定所有这些。也许这有帮助。但正如我所说,当您返回 404 时,我认为这不会是 TLS 或 SSL 问题。

server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://192.168.0.12$request_uri;
}

server {
    listen               443;
    ssl                  on;
    ssl_certificate      /home/pi/web/localhost.crt;
    ssl_certificate_key  /home/pi/web/localhost.key;
    ssl_ciphers          HIGH:!aNULL:!MD5;
    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;


location /FindMotion/ {
        proxy_pass http://localhost:5000/;
        proxy_http_version 1.1;
        proxy_set_header Connection keep-alive;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host   $http_host;
        proxy_set_header X-Forwarded-Proto  http;
        proxy_set_header X-Forwarded-Path   /FindMotion;
}
}
}