Apache2

網站響應 IP,但不響應域

  • March 5, 2021

我在 AWS Lightsail Ubuntu 20.04 實例上託管了一個基於 Django 的網站,該網站在 Apache2 上執行。

使用 ip 18.133.43.205 時可以訪問該網站。但是當我嘗試使用域 roosta.xyz 搜尋我的網站時,連接超時。

DNS 使用 AWS 的名稱伺服器。我不認為 DNS 是問題,因為當我進行 whois 查找時,它會顯示 AWS 名稱伺服器,當我在 linux 終端中執行 dig roosta.xyz 時,會返回正確的 ip。

幾天前,我收到了來自伺服器的響應,但它要求使用 https,但我沒有 ssl 證書,所以我的瀏覽器嚇壞了。我不想使用https。但是在干預伺服器後,試圖阻止它想要使用 https,我現在又回到了連接超時。

另一件事是我在自己機器的終端上執行 curl roosta.xyz 並返回網頁的 html?那麼chrome怎麼沒有得到呢?!

這是 apache 虛擬主機配置文件的副本:

<VirtualHost *:80>
   ServerName www.roosta.xyz
   ServerAdmin webmaster@localhost
   ServerAlias roosta.xyz
   DocumentRoot /var/www/html

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined

   Alias /static /home/ubuntu/myWebsite/static
   <Directory /home/ubuntu/myWebsite/static>
       Require all granted
   </Directory>

   <Directory /home/ubuntu/myWebsite/myWebsite>
       <Files wsgi.py>
           Require all granted
       </Files>
   </Directory>

   WSGIScriptAlias / /home/ubuntu/myWebsite/myWebsite/wsgi.py
   WSGIDaemonProcess myWebsite_app python-path=/home/ubuntu/myWebsite python-home=/home/ubuntu/myWebsite/venv
   WSGIProcessGroup myWebsite_app 
</VirtualHost>

Apache2ctl -S

VirtualHost configuration:
*:80                   roosta.xyz (/etc/apache2/sites-enabled/myWebsite.conf:2)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

在網上搜尋了幾個小時後,我完全被難住了。我非常樂意提供更相關的程式碼或 lightsail 設置圖片來幫助解決我的問題。

  1. 您的問題的根源在於您的伺服器沒有響應 HTTPS。

(如:在 TCP 埠 443 上根本沒有響應。我的連接嘗試只是不得不超時,因為您的伺服器甚至沒有返回“連接被拒絕”數據包。這通常是 DROP 而不是 REJECT 防火牆策略的效果) . 2. 另一方面,Chrome 拒絕在純 HTTP 上連接,因為它確定您的域的HSTS 策略 不允許這樣做。由於該政策,Chrome 會調整任何http://www.roosta.xyzURL 並將其更改httphttpsURL。

從 Chrome 測試 HSTS 策略:得到chrome://net-internals/#hsts

HSTS 檢查frosts.xyz

您的域是預載入的 HSTS 列表的一部分(可能在https://hstspreload.org/上送出)

請參閱:https://source.chromium.org/chromium/chromium/src/+/master:net/http/transport_security_state_static。 json

要解決這個問題,您要麼需要將您的域從 HSTS pe-load 列表中刪除(短期內不會發生),要麼您需要設置 TLS 以便您的站點顯示在 https 上。

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