我正在尝试将与jupyterhub一起运行的jupyterlab集成到iframe中。我在配置文件中进行了所有必需的更改。在jupyter_notebook_config.py中,我进行了以下更改。
c.NotebookApp.tornado_settings = {'headers': {
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': 'frame-ancestors http://localhost:9005'
}}
而在jupyterhub_config.py中,我添加了以下内容
c.JupyterHub.tornado_settings = {'headers': {
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': 'frame-ancestors http://localhost:9005'
}}
但是,当我尝试在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
请注意,以上命令要求安装jupyter笔记本(pip3 install jupyterhub笔记本)
安装后,如果在加载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
注意:您可以使用以下命令生成jupyterhub配置文件:jupyterhub --generate-config
c.Spawner.args = [ '--config=/home/shared_config/jupyter_notebook_config.py']
使用以下命令重新加载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']
-/home/shared_config/jupyter_notebook_config.py
c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}}
一些有用的参考和相关问题:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句