docker - 如何正确配置NGINX作为tine20 docker容器(与Apache2一起运行)的反向代理?

标签 docker nginx nginx-reverse-proxy

我正在尝试为tine20 docker容器(使用apache2作为web服务器)将nginx配置为反向代理(使用通过network_mode: host运行的nginx docker容器)。

我正在使用以下反向代理配置:

server {
    listen                    443 ssl http2;
    server_name               ${DOMAIN};

    ssl_certificate           /etc/letsencrypt/live/${PATH}/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/${PATH}/privkey.pem;
    ssl_dhparam               /etc/ssl/dhparams.pem;

    ssl_ciphers               "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA";
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_session_cache         shared:SSL:10m;
    add_header                Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" always;
    add_header                X-Frame-Options SAMEORIGIN;
    add_header                X-Content-Type-Options nosniff;
    ssl_session_tickets       off;
    ssl_stapling              on;
    ssl_stapling_verify       on;

    root                      /etc/letsencrypt/webrootauth;

    location / {
    proxy_pass              http://${UPSTREAM};
    proxy_set_header        Host $host;
    proxy_set_header        X-Forwarded-For $remote_addr;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_cache             anonymous;
    proxy_buffering         off;
    proxy_http_version      1.1;
    proxy_set_header        Upgrade $http_upgrade;
    proxy_set_header        Connection $http_connection;
    }

    location /.well-known/acme-challenge {
    alias                   /etc/letsencrypt/webrootauth/.well-known/acme-challenge;
    location ~ /.well-known/acme-challenge/(.*) {
        add_header            Content-Type application/jose+json;
    }
    }
}

server {
    listen                    80;
    server_name               ${DOMAIN};
    return                    301 https://$server_name$request_uri;
}

tine20容器中的Apache使用以下配置:
# Apache and PHP configuration for Tine 2.0
#

# Alias /tine20                      /usr/share/tine20
# Alias /Microsoft-Server-ActiveSync /usr/share/tine20/Microsoft-Server-ActiveSync

# some people prefer a simple URL like http://tine20.example.org
# in this case you also have to disable to Alias lines above
<VirtualHost *:80>
DocumentRoot /usr/share/tine20
ServerName   ${SERVER_NAME}
</VirtualHost>

<Directory /usr/share/tine20>
    Order Allow,Deny
    Allow from all

    DirectoryIndex index.php

    Options +ExecCGI

    <IfModule mod_php5.c>
        Define PHP_MODULE_INSTALLED
    </IfModule>

    <IfModule mod_php7.c>
        Define PHP_MODULE_INSTALLED
    </IfModule>

    <IfDefine PHP_MODULE_INSTALLED>
        php_admin_value max_input_time          120
        php_admin_value include_path            .:/usr/share/tine20:/usr/share/tine20/library:/usr/share/tine20/vendor/zendframework/zendframework1/library:/etc/tine20
        php_admin_value open_basedir            /usr/share/tine20:/var/lib/tine20:/tmp:/usr/share/php:/etc/tine20:/var/log/tine20
        php_admin_value session.gc_maxlifetime  86400
        php_admin_value memory_limit            128M
        php_admin_value upload_max_filesize     20M
        php_admin_value post_max_size           20M

        php_admin_value safe_mode               off
        php_admin_flag  display_errors          off
        php_admin_flag  log_errors              on
        php_admin_flag  magic_quotes_gpc        off
        php_admin_flag  magic_quotes_runtime    off
        php_admin_flag  register_globals        off

        <IfModule mod_headers.c>
            # activate zlib compression and remove content-length header
            # this is necessary because of this php bug: https://bugs.php.net/bug.php?id=44164
            php_admin_flag  zlib.output_compression on
            <FilesMatch "\.php$">
                Header unset Content-Length
            </FilesMatch>
        </IfModule>

        php_value       max_execution_time      90
    </IfDefine>

    <IfModule mod_rewrite.c>
        RewriteEngine on

        # needs to be adopted if tine20 is not in subdir /tine20
        RewriteBase /tine20

        # ActiveSync
        RewriteRule ^Microsoft-Server-ActiveSync index.php?frontend=activesync         [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

        # OpenID
        RewriteRule ^users/(.*)                  index.php?frontend=openid&username=$1 [L,QSA]

        # WebDAV / CalDAV / CardDAV
        RewriteCond %{REQUEST_METHOD} !^(GET|POST)$
        RewriteRule ^$                           index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

        RewriteRule ^addressbooks                index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
        RewriteRule ^calendars                   index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
        RewriteRule ^webdav                      index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
        RewriteRule ^principals                  index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
        RewriteRule ^remote.php                  index.php?frontend=webdav             [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

        # Anonymous downloads
        RewriteRule ^download/get/(.*)           index.php?method=Download.downloadNode&path=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
        RewriteRule ^download/show/(.*)          index.php?method=Download.displayNode&path=$1  [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

        # Routing
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php?doRouting=1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
</IfModule>

    <IfModule mod_expires.c>
        ExpiresActive on

        ExpiresByType image/gif              "access plus 1 month"
        ExpiresByType image/jpeg             "access plus 1 month"
        ExpiresByType image/png              "access plus 1 month"
        ExpiresByType text/css               "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 month"
    </IfModule>

    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/json

        <IfModule mod_headers.c>
            # properly handle requests coming from behind proxies
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
    </IfModule>
</Directory>

使用此配置时,我遇到了在Firefox开发者控制台日志中显示的以下错误:
Mixed Content: The page at 'https://localhost/' was loaded over HTTPS, but requested an insecure script 'http://localhost/Tinebase/js/fatClient.js-c79fcf9f7cddb7b5e69e-FAT.js'. This request has been blocked; the content must be served over HTTPS. (index):1 Mixed Content: The page at 'https://localhost/' was loaded over HTTPS, but requested an insecure script 'http://localhost/index.php?method=Tinebase.getJsTranslations&locale=en&app=all&version=ce92dfccacd6bf202116c419e856ffea17b37604'. This request has been blocked; the content must be served over HTTPS.
要重现此错误并可以尝试进行配置,请遵循此repository中的指示。

出现此错误的问题是,从Docker容器托管的tine20应用程序在访问登录页面(https://localhost/)时永久卡住,因为脚本文件被浏览器阻止。

如果您从开发者控制台复制所请求的http url并将m粘贴到url栏中,则脚本将被加载,并且还会正确重定向到https地址(通过301)。

现在我真的不明白为什么会出现错误以及如何正确加载内容。

最佳答案

Mixed Content: The page at 'https://localhost/' was loaded over HTTPS, but requested an insecure script 'http://localhost/Tinebase/js/fatClient.js-c79fcf9f7cddb7b5e69e-FAT.js'. This request has been blocked; the content must be served over HTTPS.



您的问题的解决方案是上述错误消息This request has been blocked; the content must be served over HTTPS.的最后一位

因此,当通过http加载页面时,您正在通过https提供一些 Assets ,并且浏览器很长时间以来都不允许这样做。

页面卡住的原因是因为必须使用服务器*FAT.js阻止的 Assets 才能呈现页面。

修复源代码,以使用相对模式(也就是没有http(s)位,只是从//example.com/path/to/something开始)将其加载到正在为页面提供服务的模式上。

在您的特定情况下,请更改为:
//localhost/Tinebase/js/fatClient.js-c79fcf9f7cddb7b5e69e-FAT.js

这样,它将使用正在加载资源的页面所使用的相同http模式加载资源。

对引发此消息的每个资源重复此操作:

This request has been blocked; the content must be served over HTTPS.

关于docker - 如何正确配置NGINX作为tine20 docker容器(与Apache2一起运行)的反向代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54637584/

相关文章:

amazon-web-services - AWS Elastic Beanstalk Docker环境变量

javascript - "right way"在一台服务器上托管多个 NodeJS 域?

http - 如何将https代理到http并启用ssl?

nginx - 为 webmin 配置 Nginx 反向代理

node.js - nginx如何获取请求客户端的ip地址

docker - Go测试失败时停止docker容器服务

copy - Dockerfile拷贝保持子目录结构

django - Django 中的并发负载处理

docker - Windows和PhpStorm上具有Docker的Xdebug

asp.net - 在 Elastic Beanstalk 上访问 Dockerized ASP.NET Core Web API 时出现 502 Bad Gateway