Nextcloud 共享在 nginx 反向代理中不起作用

Nextcloud 共享在 nginx 反向代理中不起作用

我有一個 nginx 反向代理,使用 jwilder 映像和 LetsEncrypt 設定得很好。一切運行良好,我有幾個容器按預期運行。

但是,我現在已在其中一台開發伺服器上建立了一個 nextcloud 容器,但無法使用它與具有相同設定的階段伺服器上的其他 nextcloud 容器共用檔案。

我看到的錯誤是Failed to perform action當我接受共享文件時。當我檢查登入控制台時我看到

Refused to connect to 'http://dev.domain.com/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/2' because it violates the following Content Security Policy directive: "connect-src 'self'".

我已經閱讀了一段時間了。我發現這在官方文件網站上但我無法讓它發揮作用。 nextcloud 本身有 ssl,但當我分享時,它看起來像是透過 http 提供服務的。我知道這與反向代理有關,但我不確定我是否知道如何解決這個問題。

歡迎任何幫助。

筆記

使用

圖:nextcloud:最新

圖片:瑪麗亞資料庫

圖片:jwilder/nginx-proxy:0.7.0

圖片:jrcs/letsencrypt-nginx-proxy-companion

答案1

我發現對我有用的是在代理後面的 nextcloud 容器前面使用 nginx 容器。為此,您還需要新增自己的 nginx.conf。像這樣的 ymal 文件。

version: '2'
services:
  web:
    image: nginx
    container_name: nextcloud_webserver
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    links:
      - app
    volumes_from:
      - app
    environment:
      - VIRTUAL_HOST=nextcloud_url
      - VIRTUAL_NETWORK=nextcloud_network
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=nextcloud_url
      - LETSENCRYPT_EMAIL=uremailforthe
    networks:
      - proxy-tier
    restart: unless-stopped

  app:
    image: nextcloud:fpm
    container_name: nextcloud_app
    links:
      - db
    volumes:
      - ./nextcloud/apps:/var/www/html/apps
      - ./nextcloud/config:/var/www/html/config
      - ./nextcloud/data:/var/www/html/data
    networks:
      - proxy-tier
    restart: unless-stopped

  db:
    image: mariadb
    container_name: db
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=urpassword
      - MYSQL_DATABASE=urdbname
      - MYSQL_USER=mysqluser
      - MYSQL_PASSWORD=mysqluserpassword
    networks:
      - proxy-tier
    restart: unless-stopped

networks:
  proxy-tier:
    external:
      name: nextcloud_network

然後將以下 nginx 檔案加入到運行 docker-compose up 檔案的相同位置。

user www-data;

    events {

     worker_connections 768;
    }
    http {
     upstream backend {
       server app:9000;
     }
     include /etc/nginx/mime.types;
     default_type application/octet-stream;
     server {
      listen 80;
      # Add headers to serve security related headers
      add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
      add_header X-Content-Type-Options nosniff;
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Robots-Tag none;
      add_header X-Download-Options noopen;
      add_header X-Permitted-Cross-Domain-Policies none;
      root /var/www/html;
      client_max_body_size 10G; # 0=unlimited - set max upload size
      fastcgi_buffers 64 4K;
      gzip on;
      gzip_vary on;
      gzip_min_length 10240;
      gzip_proxied expired no-cache no-store private auth;
      gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
      gzip_disable "MSIE [1-6]\.";
      index index.php;
      error_page 403 /core/templates/403.php;
      error_page 404 /core/templates/404.php;
      rewrite ^/.well-known/carddav /remote.php/dav/ permanent;
      rewrite ^/.well-known/caldav /remote.php/dav/ permanent;
      location = /robots.txt {
       allow all;
       log_not_found off;
       access_log off;
      }
      location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ {
       deny all;
      }
      location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
       deny all;
      }
      location / {
       rewrite ^/remote/(.*) /remote.php last;
       rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
       try_files $uri $uri/ =404;
      }
      location ~ \.php(?:$|/) {
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param PATH_INFO $fastcgi_path_info;
       fastcgi_param HTTPS on;
       fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
       fastcgi_pass backend;
       fastcgi_intercept_errors on;
      }
      # Adding the cache control header for js and css files
      # Make sure it is BELOW the location ~ \.php(?:$|/) { block
      location ~* \.(?:css|js)$ {
       add_header Cache-Control "public, max-age=7200";
       # Add headers to serve security related headers
       add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
       add_header X-Content-Type-Options nosniff;
       add_header X-Frame-Options "SAMEORIGIN";
       add_header X-XSS-Protection "1; mode=block";
       add_header X-Robots-Tag none;
       add_header X-Download-Options noopen;
       add_header X-Permitted-Cross-Domain-Policies none;
       # Optional: Don't log access to assets
       access_log off;
      }
      # Optional: Don't log access to other assets
      location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
       access_log off;
      }
     }
    }

相關內容