ash*_*ava 4 jupyter jupyter-notebook jupyterhub jupyter-lab
我正在尝试将与 jupyterhub 一起运行的 jupyterlab 集成到 iframe 中。我在配置文件中进行了所有必需的更改。在 jupyter_notebook_config.py 中,我进行了以下更改。
c.NotebookApp.tornado_settings = {'headers': {
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': 'frame-ancestors http://localhost:9005'
}}
Run Code Online (Sandbox Code Playgroud)
在 jupyterhub_config.py 中我添加了以下内容
c.JupyterHub.tornado_settings = {'headers': {
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': 'frame-ancestors http://localhost:9005'
}}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在 iframe 中打开http://localhost:8002/user/admin/lab URL 时,出现以下错误
Refused to display 'http://localhost:8002/user/admin/lab' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".
如果我遗漏了什么或者我的配置有问题,有人可以告诉我吗?
这是一个解决方法,
请按照以下步骤操作:
您可以使用 vim 等文本编辑器手动创建文件,也可以使用 jupyter Notebook 使用以下命令生成默认的 coinfig 文件
jupyter notebook --generate-config
Run Code Online (Sandbox Code Playgroud)
注意,上面的命令需要安装jupyter notebook(pip3 install jupyterhub notebook)
安装后,如果您在加载 tljh-config 时遇到与 ruamel.yaml 版本相关的错误,请执行以下命令: pip3 install ruamel.yaml==0.15.*
打开上面创建的 jupyter_notebook_config.py 文件并添加以下代码:
c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy':"frame-ancestors * 'self'"}}
使用以下代码更改文件的权限:
chmod -R 755 /home/shared_config/jupyter_notebook_config.py
Run Code Online (Sandbox Code Playgroud)
注意:您可以使用以下命令生成 jupyterhub 配置文件: jupyterhub --generate-config
c.Spawner.args = [ '--config=/home/shared_config/jupyter_notebook_config.py']
Run Code Online (Sandbox Code Playgroud)
使用以下命令重新加载 tljf-config:
sudo tljf-config 重新加载
快乐编码!
这是我的配置
-- /opt/tljh/config/jupyterhub_config.d/jupyterhub_config.py
c.JupyterHub.tornado_settings = {'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}}
c.Spawner.args = [ '--config=/home/ubuntu/jupyter_notebook_config.py']
Run Code Online (Sandbox Code Playgroud)
-- /home/shared_config/jupyter_notebook_config.py
c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}}
Run Code Online (Sandbox Code Playgroud)
一些有用的参考资料和相关问题:
| 归档时间: |
|
| 查看次数: |
3666 次 |
| 最近记录: |