
我在本機Raspberry Pi 盒子上設定了DnsMasq,用於將本機裝置對應到網路上的簡單路徑,例如laptop.local 我在筆記型電腦上使用WAMP 進行本機Web 開發,此設定運作得非常好,但只是為了整理URL 和出於教育目的,我如何將筆記型電腦上的子目錄(目前為“laptop.local/website”)映射到子網域,例如“website.laptop.local”
答案1
假設您的 DNS 設定正確筆記型電腦本地,您可能只需要更新 WAMP 設定即可使用適當的 Apache 虛擬主機。
配置WAMP
建立一個目錄來容納您的子網域。確保在 WAMP 安裝可以存取的位置(例如在根
www
資料夾下或旁邊)完成此操作。打開阿帕契httpd.conf(位於 Apache
conf
目錄下的 WAMP 安裝或透過對應的選單介面,例如Apache → httpd.conf
)。取消註解此行(刪除 #):
# Include conf/extra/httpd-vhosts.conf
那麼應該會變成
Include conf/extra/httpd-vhosts.conf
打開您的 Apache
conf\extra
資料夾並找到httpd-vhosts.conf
.在文件末尾添加類似以下內容:# Virtual host entry for website.laptop.local # Anything with a # is a comment <VirtualHost *:80> ServerName website.laptop.local #ServerAlias *.website.laptop.local # DocumentRoot should correspond to wherever the HTML files # for your website.laptop.local site are located. This is an example! DocumentRoot "C:/wamp/www/subdomains/my-website" ErrorLog "logs/my-website-error.log" CustomLog "logs/my-website-access.log" common # If you have any problems with "Forbidden", try uncommenting # the following (assumes Apache 2.4.x). #<Directory "C:/wamp/www/subdomains/my-website"> #AllowOverride None #Options None #Require all granted #</Directory> </VirtualHost>
確保啟用您的別名模組和虛擬主機別名模組阿帕契模組。通常,這是透過適當的選單介面(再次)完成的,例如,
Apache → Apache modules
但也可以httpd.conf
透過簡單地取消註釋適當的模組行來完成。重新啟動您的 WAMP 伺服器。
假設沒有錯誤,網址.筆記型電腦.本地現在應該可用了。