我有一个LAMP服务器configuration为服务器VHOSTs。 这里的问题是,当我尝试通过同一个局域网访问它时,我似乎尝试访问本地IP地址而不是VHOST地址。 但是,当我尝试从外部访问服务器时,它显示正确的VHOST。 我需要configurationApache以某种方式服务于正确的网站,而不是默认的网站。 我该怎么做呢?
这是我的两个VHOST条目的例子。
默认
<VirtualHost *:80> ServerAdmin [email] ServerName eresk.fi DocumentRoot /home/web/apache-webserver/public_html/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /home/web/apache-webserver/public_html/> Options -Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /home/web/apache-webserver/cgi-bin/ <Directory "/home/web/apache-webserver/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
另一个网站
<VirtualHost *:80> ServerAdmin [email] ServerName diggety.net ServerAlias *.diggety.net DocumentRoot /home/web/diggety/public_html/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /home/web/diggety/public_html/> Options -Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /home/web/diggety/cgi-bin/ <Directory "/home/web/diggety/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> <IfModule php5_mod.c> php_value session.gc_maxlifetime 604800 </IfModule> ErrorLog ${APACHE_LOG_DIR}/error_diggety.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access_diggety.log combined </VirtualHost>
这不是apache的错。 VirtualHost指令不适用于通过IP的请求。 您访问站点的局域网中的计算机会检查DNS服务器并获取外部IP。 如果服务器位于同一networking上,则networking上的适当路由器应正确parsing/路由,但对于某些路由器,情况并非总是如此。
为了testing这一点,在客户端添加自定义的DNS条目为您的域名映射到您的服务器的内部IP。 编辑/etc/hosts如果客户端是linux或C:\Windows\system32\drivers\etc\hosts如果客户端在Windows上并添加此项)(将10.0.0.1更改为服务器的内部IP):
10.0.0.1 domain.com
更新 :如果DNS解决scheme有效,您可以在内部networking上configuration自定义DNS服务器,这将允许您设置自定义DNS条目。 这样你就不需要在客户端手动设置它。