AWS实例部署Jupyter Notebook后本地访问卡顿问题求助
Let's break down the most likely issues stopping you from accessing your Jupyter Notebook locally, and walk through fixes step by step:
1. Fix Your Incomplete SSH Tunnel Command
Looking at the command you shared:
ssh -i keypair.pem -L 8157:127.0.0.1:8888 ubuntu@
This command is missing a critical piece—your EC2 instance's public IP address or DNS name at the end. Without that, SSH can't connect to your instance at all, so no tunnel is established.
Update the command to include your instance's public IP (replace 3.14.159.26 with your actual instance IP):
ssh -i keypair.pem -L 8157:127.0.0.1:8888 ubuntu@3.14.159.26
First, make sure your keypair file has the correct permissions (required for Linux/macOS):
chmod 400 keypair.pem
2. Use the Correct Protocol for Local Access
Your Jupyter output clearly shows it's running over HTTP, not HTTPS:
The Jupyter Notebook is running at: http://localhost:8888/?token=...
You're trying to access https://127.0.0.1:8157, which will cause your browser to hang—Jupyter doesn't serve HTTPS by default. Switch to the HTTP version of the URL:
- Basic address:
http://127.0.0.1:8157 - Token-protected address:
http://127.0.0.1:8157/?token=4b35857968acb4a75dc4b7fdd246c20b967dcfaaa13799c2
3. Verify the SSH Tunnel Is Active
After running the corrected SSH command, confirm the tunnel is listening on your local port 8157:
- Linux/macOS: Run this in a new terminal window:
You should see anlsof -i :8157sshprocess listed withLISTENstatus. - Windows: Open Command Prompt and run:
Look for a result where the "State" isnetstat -ano | findstr :8157LISTENING, and the PID corresponds tossh.exe(check PID details in Task Manager if needed).
If no results appear, double-check:
- Your EC2 instance is running and has a valid public IP.
- Your security group allows inbound SSH (port 22) from your local IP (your screenshot shows SSH is open to
0.0.0.0/0, which works for testing).
4. Check for Local Firewalls on the EC2 Instance
Ubuntu's default firewall (ufw) is usually disabled, but it's worth verifying:
- SSH into your EC2 instance.
- Run:
sudo ufw status - If it shows
active, either allow loopback access to port 8888:
Or temporarily disablesudo ufw allow in from 127.0.0.1 to any port 8888ufwto test:sudo ufw disable
5. Confirm Jupyter's Binding Address
From your output, Jupyter is correctly bound to localhost:8888, which works with your SSH tunnel. If you've modified Jupyter's config before, double-check the ip setting:
- SSH into your instance and open the config file (if it exists):
nano ~/.jupyter/jupyter_notebook_config.py - Look for the line:
If it's set to a specific public IP instead, change it back toc.NotebookApp.ip = 'localhost'localhostor0.0.0.0(both work with the tunnel).
Start with the first two fixes—completing the SSH command and switching to HTTP—those are the most likely culprits here!
内容的提问来源于stack exchange,提问作者John Montague

