Apache 處理 127.*.*.*:80 而不僅僅是 127.0.0.1:80

Apache 處理 127.*.*.*:80 而不僅僅是 127.0.0.1:80

我希望 Apache 只處理對 127.0.0.1 的請求,以便我可以將 127.0.0.2 等用於其他應用程序,因此我嘗試將 /etc/apache2/sites-enabled/000-default.conf 更改為

 <VirtualHost 127.0.0.1:80>
     ServerName localhost
     ServerAdmin webmaster@localhost
     DocumentRoot /var/www/html
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>

然後我重新啟動了 Apache,但它不起作用。沒有其他虛擬主機規則,輸出apachectl -S如下:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
127.0.0.1:80           localhost (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
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

答案1

Listen指令用於設定 Apache httpd 應綁定到哪些位址/連接埠組合(或上,如果你願意的話)。
當僅指定連接埠(無位址)時,表示所有位址都綁定到指定連接埠。

VirtualHost另一方面,指令是如何回應請求的配置的一部分(例如提供哪些內容等)。
在此上下文中指定的位址/連接埠用於選擇 Apache httpd 甚至應該嘗試使用此位址/連接埠的傳入請求VirtualHost

如果您只希望 Apache httpd 只綁定到127.0.0.1:80,您可以像這樣作為您唯一的Listen指令:

Listen 127.0.0.1:80

相關內容