1. 程式人生 > >docker nginx jupyter

docker nginx jupyter


docker 中nginx 和jupyter 如何反向代理

nginx 使用 docker.io/richarvey/nginx-php-fpm:latest , 配置在 /etc/nginx/sites-enables

jupyter 使用 docker.io/tensorflow/tensorflow:latest    配置在 ~/.jupyter  目錄   ip 172.17.0.7

解決wss的錯誤

                $proxy_add_x_forwarded_for; 
                 proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade"; 

nginx 配置

server{
        listen 443  ssl;
        server_name localhost;
        root   /var/www/html;
        index  index.html index.htm index.php;
        keepalive_timeout 70;
        server_tokens off;
       ssl on;
       ssl_certificate       /etc/nginx/ssl/server.crt;
        ssl_certificate_key    /etc/nginx/ssl/server.key;
        ssl_client_certificate /etc/nginx/ssl/ca-chain.cert.pem;
        ssl_verify_client      off;
        location ^~/ju  {
          proxy_pass http://172.17.0.7:8888/ju;
         #以下是一些反向代理的配置可刪除
        proxy_redirect             off; 
        #後端的Web伺服器可以通過X-Forwarded-For獲取使用者真實IP
        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";
        client_max_body_size       10m; #允許客戶端請求的最大單檔案位元組數
        client_body_buffer_size    128k; #緩衝區代理緩衝使用者端請求的最大位元組數
        proxy_connect_timeout      300; #nginx跟後端伺服器連線超時時間(代理連線超時)
        proxy_send_timeout         300; #後端伺服器資料回傳時間(代理髮送超時)
        proxy_read_timeout         300; #連線成功後,後端伺服器響應時間(代理接收超時)
        proxy_buffer_size          4k; #設定代理伺服器(nginx)儲存使用者頭資訊的緩衝區大小
        proxy_buffers              4 32k; #proxy_buffers緩衝區,網頁平均在32k以下的話,這樣設定
        proxy_busy_buffers_size    64k; #高負荷下緩衝大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k;   
      }


        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;
        location = /404.html {
                root /var/www/errors;
                internal;
        }

        location ^~ /sad.svg {
            alias /var/www/errors/sad.svg;
            access_log off;
        }
        location ^~ /twitter.svg {
            alias /var/www/errors/twitter.svg;
            access_log off;
        }
        location ^~ /gitlab.svg {
            alias /var/www/errors/gitlab.svg;
            access_log off;
        }

        # pass the PHP scripts to FastCGI server listening on socket
        #
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
                expires           5d;
        }

        # deny access to . files, for security
        #
        location ~ /\. {
                log_not_found off; 
                deny all;
        }
        
        location ^~ /.well-known {
                allow all;
                auth_basic off;
        }
       
   
}

import os
from IPython.lib import passwd

c = c  # pylint:disable=undefined-variable
c.NotebookApp.ip = '0.0.0.0'  # https://github.com/jupyter/notebook/issues/3946
c.NotebookApp.port = int(os.getenv('PORT', 8888))
c.NotebookApp.open_browser = False

# sets a password if PASSWORD is set in the environment
if 'PASSWORD' in os.environ:
  password = os.environ['PASSWORD']
  if password:
    c.NotebookApp.password = passwd(password)
  else:
    c.NotebookApp.password = ''
    c.NotebookApp.token = ''
  del os.environ['PASSWORD']
c.NotebookApp.base_project_url = '/ju'
c.NotebookApp.base_url ='/ju'