2014-01-29 59 views
0

我想重定向子域名到https(當請求到達http),但不是所有。 我正在使用FuelPHP,我正在清理URL,以便index.php不可見。 我寫了這個配置,但是這並不像預期的那樣工作。 HTTPS請求正在通過,但在請求使用HTTP時,服務器無法發送答案。lighttpd http到https

$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" 
    } 
} 

我對某些子域(demo,faq,...)進行了特定的配置,這些子域是從開始過濾的。 所有未過濾的子域都由應用程序動態管理,因此必須保持可訪問狀態,但僅限於SSL。

+0

你說「服務器無法發送答案」,這是什麼意思?如果你請求一個http頁面,服務器返回的是什麼?另外,您是否閱讀過lighttpd [http to https](http://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps)文檔? – Macattack

+0

我使用Chrome Inspect元素跟蹤記錄的網絡活動。瀏覽器發出的請求在使用HTTP時處於待定狀態,並在使用HTTPS時得到完全解答。 –

回答

2

我看不到所有的配置,所以我不能肯定地說這是否能解決您的問題。

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") 
      } 
     } 
     .... 
    } 
} 
+0

看起來像這是行得通的。我打算玩這個,看看如何完全適應我的配置。謝謝 –

相關問題