Apache-2.2

為什麼https不起作用?

  • December 4, 2018

我正在嘗試僅將我的網站的根目錄重定向到 https。儘管發生了重寫,但 https 不會產生任何結果。瀏覽器說。connecting to thinkingmonkey.me...並停滯不前。

  • Listen 80Listen 443存在於 conf 文件中。
  • 我已經重新啟動了httpd。
  • 我正在使用正確的證書文件和私鑰文件。
  • httpd 日誌SSL 日誌中沒有錯誤(我有一個單獨的 Ssl 日誌)。
  • 即使我嘗試直接訪問https://thinkingmonkey.me ,實際上也沒有任何內容被記錄到 SSL 訪問日誌中。

Anetstat -pant | grep httpd有這個:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 :::443                      :::*                        LISTEN      1334/httpd          
tcp        0      0 :::80                       :::*                        LISTEN      1334/httpd   

.ht 訪問:

RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://thinkingmonkey.me [L,R=302]

重寫日誌數據:

我的IP - -

$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(2) 使用請求的 uri /

my-ip 初始化重寫引擎 - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(1) 通過/

my-ip - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(3)$$ perdir /mysite/ $$去除每個目錄前綴:/mysite/ ->

my-ip - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(3)$$ perdir /mysite/ $$應用模式 ‘^(.*) $ ’ to uri ’’ my-ip - - [24/Jan/2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial] (4) [perdir /mysite/] RewriteCond: input=‘80’ pattern=‘80’ => matched my-ip - - [24/Jan/2012:19:01:14 +0000] [thinkingmonkey.me/sid#7fa2335ceb18][rid#7fa2339336d8/initial] (4) [perdir /mysite/] RewriteCond: input=’/’ pattern=’^/ $ ’ => 匹配

我的 IP - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(2)$$ perdir /mysite/ $$重寫 ’’ -> ’ https://thinkingmonkey.me '

my-ip - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(2)$$ perdir /mysite/ $$使用https://thinkingmonkey.me my-ip顯式強制重定向

  • -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(1)$$ perdir /mysite/ $$轉義https://thinkingmonkey.me以重定向

my-ip - -$$ 24/Jan/2012:19:01:14 +0000 $$ $$ thinkingmonkey.me/sid#7fa2335ceb18 $$$$ rid#7fa2339336d8/initial $$(1)$$ perdir /mysite/ $$重定向到https://thinkingmonkey.me $$ REDIRECT/302 $$

這是我的虛擬主機。

<VirtualHost *:80>
    ServerName thinkingmonkey.com
    ServerAlias www.thinkingmonkey.com  www.thinkingmonkey.me

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?thinkingmonkey\.(com|me)$ [NC]
    RewriteRule ^ http://thinkingmonkey.me%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:80>
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot /mysite/
   ServerName thinkingmonkey.me
   ErrorLog logs/site-error_log
   CustomLog logs/site-access_log common
   RewriteEngine On
   RewriteLog "/var/log/rewrite.log"
   RewriteLogLevel 3
</VirtualHost>

<VirtualHost *:443>

ServerName thinkingmonkey.me

ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

SSLEngine on

SSLProtocol all -SSLv2

SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW


SSLCertificateFile /path/to/my.crt
SSLCertificateKeyFile /path/to/my.key
SSLCertificateChainFile /path/to/my.ca-bundle


<Files ~ "\.(cgi|shtml|phtml|php3?)$">
   SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
   SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

CustomLog logs/ssl_request_log \
     "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

lsof -i -P | grep 443
httpd    1334     root    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1335   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1336   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1337   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1338   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1339   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1340   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1341   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)
httpd    1342   apache    6u  IPv6   3297      0t0  TCP *:443 (LISTEN)

這裡出了什麼問題?

好的,試試這個:

telnet localhost 443

這會給出響應,還是會掛起?如果它正在響應,您應該得到如下所示的內容:

$ telnet localhost 443
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

(如果沒有安裝 telnet,則安裝它;您可以通過點擊control-]然後鍵入“q”退出 telnet 會話)

如果您能夠在本地界面上連接到 Web 伺服器(並且 Web 伺服器正在執行,鑑於您的日誌),那麼存在防火牆問題(我知道您說您沒有設置防火牆,但這會確認)。在這種情況下,執行:

iptables -L -n

並發布結果。

更新

根據評論,這是一個 EC2 實例,因此請查看與此實例關聯的安全組。確保您在安全組中允許 tcp/443。

這樣的事情可能會有所幫助:

http://cloud-computing.learningtree.com/2010/09/24/understanding-amazon-ec2-security-groups-and-firewalls/

引用自:https://serverfault.com/questions/353189