【问题标题】:lighttpd http to httpslighttpd http 到 https
【发布时间】:2014-01-29 11:09:17
【问题描述】:

我想将子域重定向到 https(当请求到达 http 时),但不是全部。 我正在使用 FuelPHP,我正在清理 url,以便 index.php 不可见。 我写了这个配置,但没有按预期工作。 HTTPS 请求正在通过,但是当使用 HTTP 请求时,服务器无法发送应答。

    $HTTP["host"] !~ "^(demo|faq|help|forums|mail|www)\.(domain\.com)$" {
    $HTTP["host"] =~ "^(.+\.)?(domain\.com)$" {
    $SERVER["socket"] == ":80" {
        url.redirect = ( "^/(.*)" => "https://%1/$1" )
    }
    $SERVER["socket"] == ":443" {
        ssl.engine = "enable" 
        ssl.pemfile = "/etc/lighttpd/certs/domain.com.pem"
    }
    server.document-root = "/home/domain/beta/public"
    server.errorlog = "/var/log/lighttpd/domain/beta/error.log"
    accesslog.filename = "/var/log/lighttpd/domain/beta/access.log"

    setenv.add-environment = ("FUEL_ENV" => "production")

    url.rewrite-once = (
        "/(.*)\.(.*)" => "$0",
        "/(js|ico|gif|jpg|png|swf|css|html)/" => "$0",
        "^/([^.]+)$" => "/index.php/$1")

    server.error-handler-404 = "/index.php"
  }
}

我有一些从一开始就被过滤的子域(演示、常见问题、...)的特定配置。 所有未过滤的子域都由应用程序动态管理,因此必须保持可访问性,但只能在 SSL 下访问。

【问题讨论】:

  • 你说“服务器发送应答失败”,这是什么意思?如果你请求一个 http 页面,服务器会返回什么?另外,您是否阅读过 lighttpd http to https 文档?
  • 我使用 Chrome Inspect Element 追踪并记录了网络活动。有一个来自浏览器的请求在使用 HTTP 时处于待处理状态,而在使用 HTTPS 时完全得到答复

标签: configuration https lighttpd


【解决方案1】:

我看不到你的所有配置,所以我不能确定这是否能解决你的问题。

Lighttpd 应该默认监听 80 端口,所以我没有指定它。

# Ssl config shouldn't be in a conditional
$SERVER["socket"] == ":443" {
    ssl.engine = "enable" 
    ssl.pemfile = "/etc/lighttpd/certs/domain.com.pem"
}

$HTTP["host"] !~ "^(demo|faq|help|forums|mail|www)\.(domain\.com)$" {
    $HTTP["host"] =~ "^(.+\.)?(domain\.com)$" {
        # Use the doc specified method of detecting http
        $HTTP["scheme"] == "http" {
            # capture vhost name with regex conditiona -> %0 in redirect    pattern
            # must be the most inner block to the redirect rule
            $HTTP["host"] =~ ".*" {
                url.redirect = (".*" => "https://%0$0")
            }
        }
        ....
    }
}

【讨论】:

    猜你喜欢
    • 2013-11-05
    • 1970-01-01
    • 2016-02-28
    • 2019-01-15
    • 2011-04-15
    • 2020-09-18
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多