nginx反向代理jupyter實踐
1.jupyter配置
打開配置文件 /home/jack/.jupyter/jupyter_notebook_config.py

2.反向代理配置
這個/jack/與上面添加的對應
location /jack/ {
proxy_pass http://192.168.196.164:8888/jack/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#這是代理網(wǎng)站的資源,可以查看但不能下載
add_header Content-Disposition "inline";
add_header X-Content-Type-Options "nosniff";
}proxy_http_version 1.1顯然意思是指定http版本為1.1, 但是為什么呢? 你自己試試不就知道了如果不加的話, 在Notebook中將無法連接到內(nèi)核, 一直會顯示disconnected.
這個是資源禁止訪問且禁止下載
location ~ \.(zip|rar|sql|bak|gz|7z|py|pdf|doc|docx|xls|xlsx|out)$ {
add_header Content-Disposition "inline";
add_header X-Content-Type-Options "nosniff";
# return 404;
}瀏覽器禁止下載
location /jack/ {
#rewrite /jack/files/* /1111;
rewrite /jack/files/* /404 permanent;
#rewrite /jack/files/(.*)$ /404;
proxy_pass http://192.168.206.25:8888/jack/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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";
add_header Content-Disposition "inline";
# add_header X-Content-Type-Options "nosniff";
add_header X-Content-Type-Options "nosniff";
}例:
more /etc/nginx/conf.d/default.conf
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ict-cloud.thupdi.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ict-cloud.thupdi.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
server_name AA.BB.com;
charset utf-8;
client_max_body_size 500m;
# tomcat 81端口
location / {
proxy_pass http://127.0.0.1:81/;
}
location /v2/ {
proxy_pass http://IP:81/;
}
# 由于81端口下有應用是以thcloud開頭的,所以這個地方需要使用正則表達式匹配
location /thcloud/ {
proxy_pass http://127.0.0.1:8081/thcloud/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_read_timeout 5m;
}
location /new/thcloud/ {
proxy_pass http://172.30.11.155:8081/thcloud/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade,keep-alive";
tcp_nodelay on;
proxy_http_version 1.1;
proxy_buffering off;
proxy_request_buffering off;
proxy_set_header X-Accel-Buffering no;
proxy_max_temp_file_size 0;
}
location /sjzl/ {
proxy_pass http://IP:9090/sjzl/;
}
location /geoserver/ {
proxy_pass http://IP:8080/geoserver/;
}
location /jupyter {
proxy_pass http://IP:8000/;
}
location /hub {
proxy_pass http://IP:8000/hub/;
}
location /user/jupyteradmin {
proxy_pass http://IP:8000/user/jupyteradmin;
}
location /user/jupyterhub {
proxy_pass http://IP:8000/user/jupyterhub;
}
#0218
#這個/jupyterhub/與上面添加的對應
location /jupyterhub/ {
proxy_pass http://IP:8000/jupyterhub/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#這是代理網(wǎng)站的資源,可以查看但不能下載
add_header Content-Disposition "inline";
add_header X-Content-Type-Options "nosniff";
}
# proxy_http_version 1.1顯然意思是指定http版本為1.1, 如果不加的話, 在Notebook中將無法連接到內(nèi)核, 一直會顯示disconnected.
#這個是資源禁止訪問且禁止下載
location ~ \.(zip|rar|sql|bak|gz|7z|py|pdf|doc|docx|xls|xlsx|out)$ {
add_header Content-Disposition "inline";
add_header X-Content-Type-Options "nosniff";
# return 404;
}
#瀏覽器禁止下載
#location /jupyterhub/ {
location // {
#rewrite /jupyterhub/files/* /1111;
rewrite /jupyterhub/files/* /404 permanent;
#rewrite /jupyterhub/files/(.*)$ /404;
proxy_pass http://IP:8000/jupyterhub/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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";
add_header Content-Disposition "inline";
# add_header X-Content-Type-Options "nosniff";
add_header X-Content-Type-Options "nosniff";
}
location ~ ^/.well-known/acme-challenge {
allow all;
root /var/www/html;
try_files $uri = 404;
break;
}
location /arcgis/ {
proxy_pass http://127.0.0.1:6080;
proxy_redirect off;
}
# arcgis服務 重定向 (IP訪問轉域名訪問)
location /arcgis/rest/services/ {
proxy_pass http://127.0.0.1:6080/arcgis/rest/services/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 80;
server_name AA.BB.com;
location / {
return 301 https://$host$request_uri;
}
if ($host = ict-cloud.thupdi.com) {
return 301 https://$host$request_uri;
}
}總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
nginx配置教程之a(chǎn)dd_header的坑詳解
這篇文章主要給大家介紹了關于nginx配置教程之a(chǎn)dd_header坑的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-02-02
Nginx配置之虛擬主機server_name優(yōu)先級方式
本文主要介紹了Nginx配置文件中不同匹配規(guī)則的優(yōu)先,包括精確匹配、以星號開頭的最長通配符、以星號結尾的最長通配符以及第一個正則表達式匹配,總結了Nginx處理匹配規(guī)則的優(yōu)先機制,以及注意事項2026-04-04
nginx: [warn] "log_format" directive used only on "http" lev
這篇文章主要介紹了nginx: [warn] "log_format" directive used only on "http" level 解決方法,需要的朋友可以參考下2014-08-08
Nginx轉發(fā)需求querystring轉寫示例解析
這篇文章主要為大家介紹了Nginx轉發(fā)需求querystring轉寫示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08

