操作系统等 在主机 Ubuntu 18.04.6 LTS 上的 Virtualbox 5.2.42 内的 Lubuntu 20.04 上进行开发
我正在使用 php 在本地主机上提供一个网站:
php -S 0.0.0.0:8080 -t /home/alan/DEV/
index.html 是
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="main"></div>
<script src="/main.js"></script>
<script src="/script.js"></script>
</body>
</html>
Chromium 在
localhost:8080
查看页面没有问题。直到最近,Firefox 也没有。
但是,我只是尝试在 Firefox 122.0.1 上连接。页面没有任何内容显示,并且我在浏览器控制台中收到以下错误:
Content-Security-Policy: The page's settings blocked the loading of a resource at data: ("media-src"). localhost:8080
Content-Security-Policy: The page's settings blocked the loading of a resource at http://localhost:8080/main.js ("script-src-elem"). localhost:8080
Content-Security-Policy: The page's settings blocked the loading of a resource at http://localhost:8080/script.js ("script-src-elem"). localhost:8080
在 Firefox 中查看
about:config
,并在 content-security
上搜索,我看到以下内容:
extensions.webextensions.base-content-security-policy
:
script-src 'self' https://* http://localhost:* http://127.0.0.1:* moz-extension: blob: filesystem: 'unsafe-eval' 'wasm-unsafe-eval' 'unsafe-inline';
extensions.webextensions.base-content-security-policy.v3
:
script-src 'self' 'wasm-unsafe-eval';
extensions.webextensions.default-content-security-policy
:
script-src 'self' 'wasm-unsafe-eval';
extensions.webextensions.default-content-security-policy.v3
:
script-src 'self'; upgrade-insecure-requests;
我尝试将
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
添加到我的 index.html 文件的头部,但这没有什么区别(除了它部分搞乱了 Chromium 上的页面布局)。
经过进一步调查,我发现主机系统上的 Firefox 113.0.2 确实 显示了我的网站。但是,在主机系统上,我必须使用 IP 地址 192.168.2.23:8080 而不是 localhost:8080。使用 IP 地址也适用于本地系统。