为什么我无法访问远程Jupyter Notebook服务器?

问题描述 投票:35回答:11

我在我的centos6.5服务器上启动了一个Jupyter Notebook服务器。而jupyter正在运行

[I 17:40:59.649 NotebookApp] Serving notebooks from local directory: /root
[I 17:40:59.649 NotebookApp] 0 active kernels 
[I 17:40:59.649 NotebookApp] The Jupyter Notebook is running at:https://[all ip addresses on your system]:8045/
[I 17:40:59.649 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

当我想在同一局域网中远程访问Jupyter时,比如打开http://192.168.1.111:8045/,我根本无法打开Jupyter页面。顺便说一句,我可以成功访问远程centos服务器。

可能的原因是什么?

jupyter-notebook
11个回答
75
投票

您是否配置了jupyter_notebook_config.py文件以允许外部连接?

默认情况下,Jupyter Notebook仅接受来自localhost的连接(例如,来自运行它的同一台计算机)。通过将NotebookApp.allow_origin选项从默认的''修改为'*',您可以在外部访问Jupyter。

c.NotebookApp.allow_origin = '*' #allow all origins

您还需要更改笔记本将侦听的IP:

c.NotebookApp.ip = '0.0.0.0' # listen on all IPs

Documentation on the Jupyter Notebook config file.


0
投票

任何仍然卡住的人 - 按照C:\Users\syurt\AppData\Local\Continuum\anaconda3\envs\myenv\share\jupyter\jupyter_notebook_config.py 上的说明操作。

基本上:

  1. 按照AWS最初描述的步骤操作。 正常打开SSH。 this page Jupyter笔记本
  2. 不要剪切和粘贴任何东西。而是打开一个新的终端窗口而不关闭第一个终端窗口。
  3. 在新窗口中输入SSH命令,如上面的链接所述。
  4. 打开Web浏览器并转到http://127.0.0.1:8157

0
投票

如果您仍然遇到问题而且您正在运行类似EC2 AWS实例的东西,则可能只是通过AWS控制台打开端口。

source activate python3


35
投票

我设法通过ip使用下面显示的命令访问我的本地服务器:

jupyter notebook --ip xx.xx.xx.xx --port 8888

用你的jupyter服务器的本地ip替换xx.xx.xx.xx


16
投票

James023已经说明了正确的答案。只是格式化它

如果您尚未配置jupyter_notebook_config.py文件

步骤1:通过在控制台中键入此行来生成文件

jupyter notebook --generate-config

第2步:编辑值

gedit  /home/koushik/.jupyter/jupyter_notebook_config.py

(在任何地方添加以下两行,因为默认值仍然被评论)

c.NotebookApp.allow_origin = '*' #allow all origin

c.NotebookApp.ip = '0.0.0.0'#listen on all IPs

第3步:关闭gedit,以防您的端口被阻止

qazxsw poi #enable your tcp:8888 port,这是你默认的jupyter端口

Step4:设置密码

sudo ufw allow 8888#它会提示输入密码

Step5:启动jupyter

jupyter notebook password

并像jupyter notebook 一样连接?


10
投票

在RedHat 7中,我们需要在运行Jupiter命令之前允许特定端口。说端口是http://xxx.xxx.xxx.xxx:8888/login

8080

然后我们可以正常运行它。例如,使用:

iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT

或者你喜欢什么。


3
投票

另一个原因可能是防火墙。我们甚至有同样的问题

jupyter notebook --ip xx.xx.xx.xxx --port xxxx。

然后它变成了我们新的centOS7上的防火墙。


2
投票

从您的命令行,我们可以看到您的jupyter服务器正常运行。您无法访问远程jupyter服务器的原因是您的远程centos6.5服务器的防火墙规则阻止来自您本地浏览器的传入请求,即。阻止你的TCP:8045端口。 jupyter notebook --ip 0.0.0.0 --no-browser --port=8080 --allow-root sudo ufw allow 80 # enable http server sudo ufw allow 443 # enable https server 然后尝试再次访问你的jupyter。


0
投票

那是你的私人IP地址吗?如果是这样,你将需要使用你的公共。去ipchicken找出它是什么。我知道你在同一个局域网中,但试试这个是否能解决任何问题。


0
投票

或者,您可以创建到服务器的隧道:

sudo ufw allow 8045  # enable your tcp:8045 port

然后在浏览器中打开ssh -i <your_key> <user@server-instance> -L 8888:127.0.0.1:8888

如果您没有identity_file,也可以省略127.0.0.1:8888


0
投票

如果您使用的是Conda环境,则应重新设置配置文件。文件位置将是这样的。我在Conda中创建env之后没有设置配置文件,那是我的连接问题。

-i <your_key>
© www.soinside.com 2019 - 2024. All rights reserved.