1.准备工作

python(x,y),就省去了装这些东西,快速且无痛,推荐。

2.生成密码


notebook的登陆密码,防止被别人随意使用。打开IPython,输入

from IPython.lib import passwd 

 

  passwd()



python中openssl怎么安装 openssl python_配置文件





把引号里的保存下来,就是'sha1:c70.....'这一串,一会儿会用到。

3.制作SSL证书,稍微复杂些,不过一步步来应该没问题。

这里首先要安装OpenSSL。打开http://slproweb.com/products/Win32OpenSSL.html,下载Visual C++ 2008 RedistributablesWin32 OpenSSL v1.0.1g Light,先装2008 Redistributables那个,再装OpenSSL v1.0.1 Light,装在C盘就好,也不大。

装后面那个东西的时候,我在这里选择了第一个选项,结果总是提示有程序正在占用什么巴拉巴拉,选第二个就好了,应该是个例吧。


python中openssl怎么安装 openssl python_Win32_02


将C:\OpenSSL-Win32\bin添加到Path中


python中openssl怎么安装 openssl python_python中openssl怎么安装_03

打开cmd或powershell,进入某个你认识的路径下,输入下面的命令,生成一个名为mycert.pem的SSL证书


<span style="color: rgb(0, 0, 0);">openssl req </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span style="color: rgb(0, 0, 0);">x509 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span style="color: rgb(0, 0, 0);">nodes </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span style="color: rgb(0, 0, 0);">days </span><span class="lit" style="color: rgb(0, 102, 102);">365</span><span style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span style="color: rgb(0, 0, 0);">newkey rsa</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="lit" style="color: rgb(0, 102, 102);">1024</span><span style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span style="color: rgb(0, 0, 0);">keyout mycert</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span style="color: rgb(0, 0, 0);">pem </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="kwd" style="color: rgb(0, 0, 136);">out</span><span style="color: rgb(0, 0, 0);"> mycert</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span style="color: rgb(0, 0, 0);">pem</span>




生成证书过程中会出现很多问题,什么国家啊(中国CN),省市啊,公司名啊等等,英语填上就得了,不是大问题。

4.为服务器创建配置文件

还是在cmd或powershell下,输入


<span  style="color: rgb(0, 0, 0);">ipython profile create nbserver</span>





这样就会在C:\Users\Administrator\.ipython下生成一个profile_nbserver文件夹,保存服务器的配置信息,进入该文件夹,用编辑器打开ipython_notebook_config.py文件,在这里编辑详细的配置信息。这里除了

c = get_config()

都是注释的,需要自己进行修改,至少应该修改下面几条,可Ctrl+F搜索:

# The port the notebook server will listen on. 
 
 c.NotebookApp.port = 9999   (这里把服务器端口改为了9999)   

  # The full path to an SSL/TLS certificate file. 
 
 c.NotebookApp.certfile = u'C:\\Users\\Administrator\\mycert.pem'    (这里引号中是你刚刚创建的mycert.pem证书所在路径,  注意用\\分割)   

  # The string should be of the form type:salt:hashed-password. 
 
 c.NotebookApp.password = u'sha1:715a2d46a1b0:682e6cce8d37'    (这里引号中是你设置密码后产生的那一串字符)

保存后就配置完成了。



5.启动服务器


还是在cmd或powershell下,输入


ipython notebook --profile=nbserver

powershell就会显示



python中openssl怎么安装 openssl python_python中openssl怎么安装_04



一切顺利的话,浏览器会发出安全警告,接受就好了,因为自己制作的证书不被识别是很正常的



python中openssl怎么安装 openssl python_SSL_05



看到左上角的9999了吗,说明你的配置文件生效了,输入密码,就可以享受notebook了。