typecho / Dockerfile

Docker Image packaging for Typecho
https://hub.docker.com/r/joyqi/typecho
GNU General Public License v2.0
88 stars 9 forks source link

使用 https 访问安装界面错乱无法安装 #12

Closed Dev-Wiki closed 2 years ago

Dev-Wiki commented 2 years ago

docker配置:

version: '3'

services:    
  typecho-server:
    image: joyqi/typecho:nightly-php7.4-apache
    volumes:
      - ./:/app/usr 
    environment:
      TIMEZONE: Asia/Shanghai
      MEMORY_LIMIT: 100m
      MAX_POST_BODY: 50m
    ports:
      - "80:80"

绑定了域名, 使用 https 访问界面如下:

image

![Uploading image.png…]()

使用 http 访问正常 image

Dev-Wiki commented 2 years ago

查看了 install.php代码:

    public function isSecure(): bool
    {
        return (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && !strcasecmp('https', $_SERVER['HTTP_X_FORWARDED_PROTO']))
            || (!empty($_SERVER['HTTP_X_FORWARDED_PORT']) && 443 == $_SERVER['HTTP_X_FORWARDED_PORT'])
            || (!empty($_SERVER['HTTPS']) && 'off' != strtolower($_SERVER['HTTPS']))
            || (!empty($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT'])
            || (defined('__TYPECHO_SECURE__') && __TYPECHO_SECURE__);
    }

应该是不符合上述条件, 我修改nginx转发如下:

plugin_host_header_rewrite = blog.devwiki.net
plugin_header_X-From-Where = frp
plugin_header_X_FORWARDED_PROTO= https
plugin_header_X_FORWARDED_PORT= 443

测试仍旧不行

Dev-Wiki commented 2 years ago

image

<head>
    <meta charset="<?php _e('UTF-8'); ?>" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><?php _e('Typecho 安装程序'); ?></title>
    <link rel="stylesheet" type="text/css" href="<?php $options->adminStaticUrl('css', 'normalize.css') ?>" />
    <link rel="stylesheet" type="text/css" href="<?php $options->adminStaticUrl('css', 'grid.css') ?>" />
    <link rel="stylesheet" type="text/css" href="<?php $options->adminStaticUrl('css', 'style.css') ?>" />
    <link rel="stylesheet" type="text/css" href="<?php $options->adminStaticUrl('css', 'install.css') ?>" />
    <script src="<?php $options->adminStaticUrl('js', 'jquery.js'); ?>"></script>
</head>

从代码看这里计算 adminStaticUrl 的 scheme 返回了 http 而非 https, 最后落到上面的函数那里, 我这里没环境无法调试

joyqi commented 2 years ago

这个应该属于https变量判断的问题,你可以放一个phpinfo文件看看这些变量是否传递过来了。

Dev-Wiki commented 2 years ago

这个应该属于https变量判断的问题,你可以放一个phpinfo文件看看这些变量是否传递过来了。

我本地docker测试也是不行, 配置如下:

version: '3'

services:    
  typecho-server:
    image: joyqi/typecho:nightly-php7.4-apache
    volumes:
      - ./:/app/usr 
    environment:
      TIMEZONE: Asia/Shanghai
      MEMORY_LIMIT: 100m
      MAX_POST_BODY: 50m
      TYPECHO_SITE_URL: https://blog.devwiki.net
    ports:
      - "80:80"
      - "4443:443"

同时 host 修改为:

127.0.0.1 blog.devwiki.net

使用 http://blog.devwiki.net/install.php 能打开页面, 但是使用https 无法打开页面.

Dev-Wiki commented 2 years ago

这个应该属于https变量判断的问题,你可以放一个phpinfo文件看看这些变量是否传递过来了。

我改了下 header, 下划线 改为 连字符 能识别了

plugin_header_X-From-Where = frp
plugin_header_X_FORWARDED_PROTO= https
plugin_header_X-FORWARDED-PROTO= https
plugin_header_X_FORWARDED_PORT= 443
plugin_header_X-FORWARDED-PORT= 443
Dev-Wiki commented 2 years ago

frp配置修改 解决此问题