装完IPython Notebook,系统默认只有本机能用,我就在想怎么能够提供一个大家一起访问的环境。
查了一下,官方文档上具体的方法,可以看官方文档Running a public notebook server,
里面介绍了通过配置SSL+password 提供全局访问,经测试成功。
但由于我想指定某些网段访问,目前还没有找到在配置文件(jupyter_notebook_config.py)如何设置,就使用了Nginx+password验证的方式,也成功了,
在此就具体介绍一下这2种方法。
A.SSL+password验证
我先介绍一下我的执行环境上如何按官方文档的操作步骤:
进入3.5.1环境
pyenv activate env351
1.生成配置文件
(env351) [seng@localhost ~]$ jupyter notebook --generate-config
Writing default config to: /home/seng/.jupyter/jupyter_notebook_config.py
2.生成密码
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:.........'
3.生成ssl证书
cd ~/.jupyter
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
4.修改配置文件jupyter_notebook_config.py,
注意官方文档说需要ssl才能打开外部访问
c.NotebookApp.base_url = '/ipython/' --制定url的path,默认是根目录
c.NotebookApp.password = u'sha1:.....' --注意和生成的配套
c.NotebookApp.ip = '*' --目前没找到制定网段的方法
c.NotebookApp.open_browser = False
c.NotebookApp.certfile = '/home/biuser/.jupyter/mycert.pem'
c.NotebookApp.keyfile = '/home/biuser/.jupyter/mykey.key'
jupyter_notebook_config.py里具体参数说明可以参考http://jupyter-notebook.readthedocs.org/en/latest/config.html
5.启动并访问
jupyter notebook
https://host:8888/ipython/tree#notebooks
B. Nginx+password验证方式
1.生成配置文件
(env351) [seng@localhost ~]$ jupyter notebook --generate-config
Writing default config to: /home/seng/.jupyter/jupyter_notebook_config.py
2.修改配置文件jupyter_notebook_config.py,
c.NotebookApp.base_url = '/ipython/' --制定url的path,默认是根目录
c.NotebookApp.password = u'sha1:.....' --注意和生成的配套
c.NotebookApp.open_browser = False
3.安装并配置Nginx
注意 proxy_set的一些参数,这些是一定需要的。
location /ipython {
allow 192.168.1.0/24; #制定自己的网段即可
deny all;
proxy_pass http://127.0.0.1:8888/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
}
4.启动并访问
jupyter notebook
nginx
http://host:nginxport/ipython/tree#notebooks