Today, I configured a Jupyter Server on Aliyun ECS, so that my iPad can use this tool to write articles and learn Python code anytime and anywhere (provided that there is a network).
The easiest way to install and manage Jupyter is Anaconda. The following uses The Linux operating system as an example. The Python version is 3.7:
$wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh $sh. / Anaconda3-2019.03 - Linux - x86_64. ShCopy the code
After the installation is complete, you will need to generate the Configuration file for Jupyter Notebook
$ jupyter notebook --generate-config
Copy the code
The configuration file is stored in ~/. Jupyter /jupyter_notebook_config.py
# Important, allow any source to access the service
c.NotebookApp.allow_origin = The '*'
No prompt to change password will be displayed when you log in for the first time
c.NotebookApp.allow_password_change = False
# HTTPS required signature
c.NotebookApp.certfile = '/your/home/.jupyter/mycert.pem'
c.NotebookApp.keyfile = '/your/home/.jupyter/mykey.key'
Listen for IP and port
c.NotebookApp.ip = '127.0.0.1'
c.NotebookApp.port = 8889
Do not open browser at startup
c.NotebookApp.open_browser = False
Copy the code
If allow_origin is not set, a Blocking Cross Origin API request for/API /contents error is reported. Certfile and keyfile are signature file paths of THE HTTPS protocol. For details, see the following.
To enable the remote service, set the login password:
$ jupyter notebook password
Enter password: ****
Verify password: ****
Copy the code
The password is recorded in the ~/. Jupyter /jupyter_notebook_config.json file, but it cannot be in plain text.
Next we set HTTPS so that all interactive data is encrypted
$ cd ~/.jupyter
$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
$ jupyter notebook --certfile=mycert.pem --keyfile mykey.key
Copy the code
The openssl command above produces a signature file that expires in 10 years (3650 days).
Next, we set up the startup of Jupyter Lab, modify the /etc/rc.local file, add the following line:
jupyter lab --allow-root --no-browser --notebook-dir=/your/workspace/ > /var/log/jupyter.log 2>&1 &
Copy the code
/your/workspace = Jupyter = Jupyter = Jupyter = Jupyter = Jupyter = Jupyter = Jupyter = Jupyter
$ jupyter lab --allow-root --no-browser --notebook-dir=/your/workspace/ > /var/log/jupyter.log 2>&1 &
$ cat /var/log/ jupyter. Log [I 16:50:56. 326 LabApp] JupyterLab extension the loaded from/anaconda3 / lib/python3.7 / site - packages/JupyterLab [I 16:50:56. 326 LabApp] JupyterLab application directory is/anaconda3 / share/jupyter/lab/I 16:50:56. 328 LabApp Serving notebooks fromlocalDirectory: /your/workspace/ [I 16:50:56.328 LabApp] The Jupyter Notebook is running: [I 16:50:56.328 LabApp] https://127.0.0.1:8889/ [I 16:50:56.328 LabApp] Use control-c to stop this server and shut down all kernels (twice to skip confirmation).Copy the code
Finally, let’s set up the nginx reverse proxy:
map $http_upgrade $connection_upgrade {
default upgrade;
' ' close;
}
server {
listen 8888;
listen [::]:8888;
ssl on;
ssl_certificate /your/home/.jupyter/mycert.pem;
ssl_certificate_key /your/home/.jupyter/mykey.key;
location / {
proxy_redirect off;
proxy_pass https://127.0.0.1:8889;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade; }}Copy the code
You can then access Jupyter Lab in your browser using https://hostname:8888. Of course, as a last resort, remember to set up firewalls, such as port 8888 in this article.
Reference:
- Running a notebook server
- www.cnblogs.com/students/p/…