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

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

正如标题所示,我正在尝试运行下一个云仅限办公室适用于 Windows 的 Docker 桌面,我正在尝试配置nginx通过接受连接局域网这样我就可以从网络上的其他计算机连接到我的服务器,所有这些计算机都在运行Windows 10

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

到目前为止我已经做到了:

1-已安装适用于 Windows 社区版的 Docker 引擎。我正在使用Docker的默认容器。

2-已安装docker-onlyoffice-nextcloud使用此处 github 页面上的说明:

https://github.com/ONLYOFFICE/docker-onlyoffice-nextcloud

3-我现在可以访问 nextcloudhttp://本地主机/主机但我无法通过网络上的任何其他计算机连接它。

问题:

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

作为参考,以下是此设置所使用的配置文件和脚本:

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

    location ~* ^/ds-vpath/ {
        rewrite /ds-vpath/(.*) /$1  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 -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

答案1

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

1-单击“开始”并输入Windows 防火墙在您的主机上。

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

3- 查找入境规则在窗口左侧,然后右键单击。

4-点击新规则..然后会出现一个新窗口。

5- 选择港口规则类型选项卡,然后点击下一个

6- 根据协议和端口选项卡,选择TCP在第一个选择中,特定本地端口:在第二个选项中输入80在文本框中。单击下一个

7- 根据行动选项卡,选择允许连接

8- 根据轮廓选项卡,选择选中所有框并单击下一个

9- 根据姓名选项卡,为规则命名,然后输入简短的描述,以便记住创建规则的原因。点击结束

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

请注意,我对这个主题的了解还远远不够,而且我边学边做。我使用这个软件包是为了个人任务和学习,所以安全对我来说不是什么大问题,而且我不知道从专家的角度来看我的这个“解决方案”有多糟糕。

因此请谨慎行事。

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

相关内容