Jupyter安装并设置反向搭理
- 安装
python -m pip install jupyter
- 配置
2.1 生成配置文件
jupyter notebook --generate-config
2.2 生成登录密码
python3 -c 'from notebook.auth import passwd; print(passwd("usepassword"));'
2.3 修改配置文件
vim ~/.jupyter/jupyter_notebook_config.py
2.4 配置文件的内容
c.NotebookApp.allow_origin = '*'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.base_url = '/'
# 设定ip访问,允许任意ip访问
c.NotebookApp.ip = '*'
c.NotebookApp.local_hostnames = ['*']
# 设置jupyter的工作路径
c.NotebookApp.notebook_dir = '/home/ifan/workspace/jupyter'
# 不打开浏览器
c.NotebookApp.open_browser = False
# 用于访问的端口,设定一个不用的端口即可
c.NotebookApp.port = 8888
# 设置登录密码, 将刚刚复制的内容替换此处的xxx
c.NotebookApp.password = ''
# 添加这个的话 直接使用token也可以直接连接 (使用pycharm可以添加上)
c.NotebookApp.token ='123456'
- 如果出现某个文件没有权限的
export XDG_RUNTIME_DIR="~/workspace/jupyter/data"
- 启动
jupyter notebook
- nginx 配置
server {
listen 80;
server_name jupyter.ifan.com www.jupyter.ifan.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name jupyter.ifan.com www.jupyter.ifan.com;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_certificate fullchain.pem; # 证书路径路径
ssl_certificate_key privkey.pem; # 证书路径
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;preload" always;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-Xss-Protection 1;
location / {
proxy_http_version 1.1;
proxy_set_header Accept-Encoding gzip;
# WebSocket support
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_next_upstream error;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 3s;
proxy_pass http://localhost:8888;
}
}