首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Apache 基於 IP 的虛擬主機配置:Listen 與 VirtualHost 指令

     編輯:程式設計疑難解答

配置模板

# httpd.conf
Listen 192.168.1.100:80
Listen 192.168.1.101:80


    DocumentRoot "/var/www/site1"
    ServerName site1.example.com
    
        Require all granted
    



    DocumentRoot "/var/www/site2"
    ServerName site2.example.com
    
        Require all granted
    

關鍵點

  1. 服務器需綁定多 IP(網卡別名或多網卡)
  2. Listen 指定 IP:Port,VirtualHost 匹配相同地址
  3. 每個虛擬主機獨立 DocumentRoot、ServerName、日誌

驗證

apachectl configtest
systemctl reload httpd
curl -H "Host: site1.example.com" https://192.168.1.100/
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved