Apache mod_dir HTTPS / HTTP redirection

ปัญหาคือ ถ้าตั้ง apache อยู่หลัง reverse proxy โดย apache <–> reverse proxy คุย HTTP กัน แต่ reverse proxy เป็น HTTPS คุยกับภายนอก

เวลา browse URL ที่เป็น directory แบบไม่ใส่ slash ปิดท้าย เช่น https://host/dirname, apache จะ redirect ไปที่ HTTP แบบมี / ปิดท้าย กล่าวคือ อะไรทำนอง http://host/dirname/ หรือ http://host/dirname/index.php <– แล้วแต่ตั้งค่า directory index ไว้

ซึ่งทำให้มีปัญหาเพราะมันหลุดจาก HTTPS ไปหา HTTP

วิธีแก้

ใส่ใน apache config

ServerName https://localhost

อ้างอิง https://serverfault.com/questions/885474/apache-redirects-from-https-to-http-when-adding-trailing-slash-to-directory

Leave a comment