如何仅通过 LAN 在 windows 上 运行 docker-onlyoffice-nextcloud

How to run docker-onlyoffice-nextcloud on windows through LAN only

如标题所示,我正在尝试 运行 nextcloudOnlyOffice in Docker Windows 的桌面,我正在尝试配置 nginx 以接受通过 LAN 的连接,这样我可以从网络上的其他计算机连接到我的服务器,所有这些计算机都是 运行ning Windows 10

虽然我已经阅读了互联网上许多有类似问题的帖子,但其中 none 似乎有我的特定设置,我无法从这里弄清楚该怎么做。

到目前为止我做了什么:

1- 除了 之外,还为 windows 社区版 安装了 docker 引擎Kitematic GUI。我使用的是 Docker 的默认容器,所以我没有安装 VirtualBox。配置 docker 使其 "DockerDesktop.vhdx" 在我的 "D:/" 驱动器上。

2- 使用 github 页面上的说明安装 docker-onlyoffice-nextcloudhttps://github.com/ONLYOFFICE/docker-onlyoffice-nextcloud.我 运行 解决了 nextcloud 服务器 无法访问 OnlyOffice 服务器 的问题,并设法 "fix"通过使用 KitematicOnlyOffice server 上打开 localhost:100 端口并配置 只有 nextcloud 服务器 中的 Office 应用程序 才能连接到它(使用 nextcloud 网络界面)。

3- 我现在可以在 http://localhost/ 上访问 主机 [=81] 上的 nextcloud =] 但我无法从网络上的任何其他计算机连接到它。

问题:

我无法弄清楚是什么阻止了我在本地连接到服务器,但我猜测它与 nginx 服务器配置有关.

尝试过:

有些人建议检查 nginx.conf 以确保 listen 80; 已启用,在我看来就像它一样。其他人建议在 listen 80; 之后使用 server_name localhost; 并且这似乎也没有做任何事情。

我检查了 Windows 共享选项以打开 网络发现 ,认为它可能与它有关,但无济于事。

作为参考,下面是用于此设置的配置文件和脚本:

docker-compose.yml

version: '3'
services:
  app:
    container_name: app-server
    image: nextcloud:fpm
    stdin_open: true
    tty: true
    restart: always
    expose:
      - '80'
      - '9000'
    volumes:
      - app_data:/var/www/html
  onlyoffice-document-server:
    container_name: onlyoffice-document-server
    image: onlyoffice/documentserver:latest
    stdin_open: true
    tty: true
    restart: always
    expose:
      - '80'
      - '443'
    volumes:
      - document_data:/var/www/onlyoffice/Data
      - document_log:/var/log/onlyoffice
  nginx:
    container_name: nginx-server
    image: nginx
    stdin_open: true
    tty: true
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - app_data:/var/www/html
volumes:
  document_data:
  document_log:
  app_data:
  mysql_data:

nginx.conf

user  www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {

    upstream backend {
      server app-server:9000;
    }


    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    map $http_host $this_host {
        "" $host;
        default $http_host;
    }

    map $http_x_forwarded_proto $the_scheme {
        default $http_x_forwarded_proto;
        "" $scheme;
    }

    map $http_x_forwarded_host $the_host {
       default $http_x_forwarded_host;
       "" $this_host;
    }

    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 off;

        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/[^\/]+/)$ /index.html;
            try_files $uri $uri/ =404;
        }

    location ~* ^/ds-vpath/ {
        rewrite /ds-vpath/(.*) /  break;
                proxy_pass http://onlyoffice-document-server;
                proxy_redirect     off;

                client_max_body_size 100m;

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

                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Host $the_host/ds-vpath;
                proxy_set_header X-Forwarded-Proto $the_scheme;
        }

        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 off;
            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;
        }

    }
}

set_configuration.sh


set -x

docker exec -u www-data app-server php occ --no-warnings config:system:get trusted_domains >> trusted_domain.tmp

if ! grep -q "nginx-server" trusted_domain.tmp; then
    TRUSTED_INDEX=$(cat trusted_domain.tmp | wc -l);
    docker exec -u www-data app-server php occ --no-warnings config:system:set trusted_domains $TRUSTED_INDEX --value="nginx-server"
fi

rm trusted_domain.tmp

docker exec -u www-data app-server php occ --no-warnings app:install onlyoffice

docker exec -u www-data app-server php occ --no-warnings config:system:set onlyoffice DocumentServerUrl --value="/ds-vpath/"
docker exec -u www-data app-server php occ --no-warnings config:system:set onlyoffice DocumentServerInternalUrl --value="http://onlyoffice-document-server/"
docker exec -u www-data app-server php occ --no-warnings config:system:set onlyoffice StorageUrl --value="http://nginx-server/"```


  [1]: https://github.com/ONLYOFFICE/docker-onlyoffice-nextcloud

如果问题出在 windows 防火墙中,请尝试禁用它并测试连接以查看它是否有效。如果确实有效,请重新激活 windows 防火墙,然后您可以继续按照以下说明操作:

1- 单击“开始”并在主机 PC 上键入 Windows Firewall

2- 单击 Windows 高级安全防火墙

3- 在window左侧找到Inbound Rules,然后右击

4- 单击 新规则.. 将出现一个新的 window。

5- 在规则类型选项卡上选择端口,然后单击下一步

6- 在Protocol and Ports选项卡下,第一项选择TCPSpecific Local Ports :在第二个选项中,在文本框中输入80。单击下一步

7- 在 操作 选项卡下,选择 允许连接

8- 在 配置文件 选项卡下,select 选中所有框并单击 下一步

9- 在 名称 选项卡下,为您的规则命名,并输入简短的描述,以便您记住创建它的原因。单击完成

此规则现在应该处于活动状态,您应该能够通过在同一网络上的另一台计算机上输入服务器的 IP 地址来连接到您的服务器。

请注意,我对这个主题知之甚少,而且我是边学边学的。我将这个软件包用于个人任务和学习,因此安全性对我来说不是大问题,而且我不知道从专家的角度来看,我的 "solution" 有多糟糕。

所以请谨慎行事。

来源:https://www.nextofwindows.com/allow-server-running-inside-wsl-to-be-accessible-outside-windows-10-host