Prestashop、Docker、反向代理 Apache 和 SSL

Prestashop, Docker, Reverse Proxy Apache and SSL

提问人:Jonathan Rendón 提问时间:10/6/2023 最后编辑:MostafaJonathan Rendón 更新时间:10/7/2023 访问量:39

问:

我正在将 Prestashop 门户迁移到 Docker,目前版本相同,我正在使用 Apache 反向代理来输出它,但它给了我一个 SSL 错误。在后台,它向我显示带有端口的 URL 警告,而在前台,它不允许我进入,它会循环并显示错误。docker 容器日志未显示任何错误

你知道我如何从HTTP强制到HTTP吗?我已经修改了 .htaccess、confic.inc 和 Link 类,但我无法让它工作。

config.inc 中添加以下代码:

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) AND $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{ $_SERVER['HTTPS'] = 'on'; }
$_SERVER['HTTP_HOST']=str_replace(':443','',$_SERVER['HTTP_HOST']);

Link.php 文件中的 $force_ssl 变量更改为 true:

public function getBaseLink($idShop = null, $ssl = null, $relativeProtocol = false)
    {
        static $force_ssl = true;  /*CHANGED*/

        if ($ssl === null) {
            if ($force_ssl === null) {
                $force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
            }
            $ssl = $force_ssl;
        }

        if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && $idShop !== null) {
            $shop = new Shop($idShop);
        } else {
            $shop = Context::getContext()->shop;
        }

        if ($relativeProtocol) {
            $base = '//'.($ssl && $this->ssl_enable ? $shop->domain_ssl : $shop->domain);
        } else {
            $base = (($ssl && $this->ssl_enable) ? 'https://'.$shop->domain_ssl : 'https://'.$shop->domain); /*CHANGED second http to https */
        }

        return $base.$shop->getBaseURI();
    }

.ht访问

 DirectoryIndex index.php
    
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
    
    
        # Sets the HTTP_AUTHORIZATION header removed by apache
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Keep legacy entry points
        RewriteRule ^(ajax|ajax_products_list|ajax-tab|backup|cron_currency_rates)\.php - [P]
        RewriteRule ^(displayImage|drawer|footer\.inc|functions|get-file-admin)\.php - [P]
        RewriteRule ^(grider|header\.inc|init|login|password|pdf|searchcron)\.php - [P]
    
        # If the URL is a legacy on index.php?controller=..., do not rewrite (let the legacy take it)
        RewriteCond  %{QUERY_STRING} (^|&)controller=|(^|&)tab=
        RewriteRule .* - [P]
    
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule .? - [L]
    
        RewriteRule .? %{ENV:BASE}/index.php [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        <IfModule mod_alias.c>
            RedirectMatch 302 ^/$ /index.php/
        </IfModule>
    </IfModule>
    
    <IfModule mod_rewrite.c>
    <IfModule mod_env.c>
    SetEnv HTTP_MOD_REWRITE On
    </IfModule>
    
    RewriteEngine on
    
    RewriteRule . - [E=REWRITEBASE:/]
    RewriteRule ^api(?:/(.*))?$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
    RewriteRule ^upload/.+$ %{ENV:REWRITEBASE}index.php [QSA,L]
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
    </IfModule>
    
    AddType application/vnd.ms-fontobject .eot
    AddType font/ttf .ttf
    AddType font/otf .otf
    AddType application/font-woff .woff
    AddType font/woff2 .woff2
    <IfModule mod_headers.c>
        <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
            Header set Access-Control-Allow-Origin "*"
        </FilesMatch>
    
        <FilesMatch "\.pdf$">
          Header set Content-Disposition "Attachment"
          Header set X-Content-Type-Options "nosniff"
        </FilesMatch>
    </IfModule>
    
    <Files composer.lock>
        # Apache 2.2
        <IfModule !mod_authz_core.c>
            Order deny,allow
            Deny from all
        </IfModule>
    
        # Apache 2.4
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
    </Files>
    <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 week"
        ExpiresByType text/javascript "access plus 1 week"
        ExpiresByType application/javascript "access plus 1 week"
        ExpiresByType application/x-javascript "access plus 1 week"
        ExpiresByType image/x-icon "access plus 1 year"
        ExpiresByType image/svg+xml "access plus 1 year"
        ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
        ExpiresByType application/font-woff "access plus 1 year"
        ExpiresByType application/x-font-woff "access plus 1 year"
        ExpiresByType font/woff2 "access plus 1 year"
        ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
        ExpiresByType font/opentype "access plus 1 year"
        ExpiresByType font/ttf "access plus 1 year"
        ExpiresByType font/otf "access plus 1 year"
        ExpiresByType application/x-font-ttf "access plus 1 year"
        ExpiresByType application/x-font-otf "access plus 1 year"
    </IfModule>
    
    <IfModule mod_headers.c>
        Header unset Etag
    </IfModule>
    FileETag none
    <IfModule mod_deflate.c>
        <IfModule mod_filter.c>
            AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype image/svg+xml
        </IfModule>
    </IfModule>
    
    <IfModule mime_module>
      AddHandler application/x-httpd-alt-php72___lsphp .php .php7 .phtml
    </IfModule>
    ```
    
    ```
    **app.conf
    **
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    
    SSLEngine on
    
    ProxyPass / http://URL:8096/
    ProxyPassReverse / http://URL:8096/
    
    <Location />
            Order allow,deny
            Allow from all
    </Location>
    
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{URL}/$1 [R=301,L]
docker Apache symfony ssl prestashop

评论


答: 暂无答案