需求
服務器性能比較好,想在服務器方便的跑程序,所以在服務器建立jupyter,然后在本地通過連接訪問到jupyter網頁,進行操作;
此外想熟悉下nginx,方便后面建網站啥的。
nginx
一款比較流行的后端服務代理程序,關於其介紹不多贅述。
下載安裝:
- 官網(http://nginx.org/en/download.html)下載tar包,解壓后運行configure,通過make編譯安裝,可以安裝到自己想要的文件地址
- 通過yum安裝,比較方便,地址是系統地址,/usr下面
配置,可以在本地選一個文件夾放配置文件,然后通過-c制定配置文件
server {
listen 8993;
server_name localhost;
location / {
root /home/xxx/work/nginx/html;
index index.html index.htm;
}
## 配置部分
client_max_body_size 1G;
location /jupyter {
proxy_pass http://127.0.0.1:11993;
proxy_connect_timeout 3s;
proxy_read_timeout 5s;
proxy_send_timeout 3s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
參數解析
- listen: 這個參數大家應該都不陌生,就是監聽的端口號。
- server_name: 瀏覽器上輸入的域名。
- location: 表示url匹配,/表示全部匹配,還可以配置不同路由。
- root: 表示匹配成功之后進入的目錄,可以指定到自己放html的路徑。
- index: 表示默認的頁面。
- proxy_connect_timeout: nginx向代理服務發起連接,第一次握手等待回應的超時時間。
- proxy_send_timeout: nginx將請求發送給代理服務的超時時間,應該是確認能正常連接之后向代理服務發送真正的業務請求。
- proxy_read_timeout: 代理服務接受到真正業務請求之后,nginx等待代理服務響應具體請求的內容的超時時間。
- client_max_body_size:最大上傳文件大小,如果jupyterlab要上傳文件,可以配置下,免得有上傳限制。
啟動服務
nginx -c nginx.conf -e nginx.log
通過-c、-e可以分別指定本地的的配置文件與報錯log文件。
jupyer-lab
安裝:直接通過pip 安裝
配置
jupyter notebook --generate-config # 生產配置文件,通常在home下的.jupyter文件夾里
jupyter-lab password # 輸入兩次密碼,會在配置文件中生存hash密碼,然后在登陸界面輸入密碼解鎖
修改/home/xxx/.jupyter/jupyter_xx_x.conf文件
c.NotebookApp.base_url = '/jupyter' # 這個看個人如何選擇,因為我在nginx中配置了local是/jupyter,所以需要在這配置baseurl
c.NotebookApp.allow_remote_access = True # 允許遠程訪問
c.NotebookApp.base_url = '/jupyter' # 設置jupyter的資源主頁路徑,即[jupyter主頁]
c.NotebookApp.ip = '127.0.0.1' # 設置了訪問該jupyter應用的來源機器只能是本機
c.NotebookApp.notebook_dir = '/home/xxx/jupyter' # jupyter工作目錄,所有在jupyter創建的文件都會保存到這里
c.NotebookApp.open_browser = False # 禁止啟動時自動開啟瀏覽器
運行jupyter,起一個后端進程,注意配置ip為localhost(127.0.0.1)或者0.0.0.0,配置port,和nginx中保持一致
python -m jupyterlab --ip 127.0.0.1 --port 11993 >/dev/null 2>&1 &