NameVirtualHosts和IP地址的configuration

所以我有site1.com和192.168.1.100

如果我使用IP地址Apache不适用于site1.com,如果我使用site1.com IP地址不起作用。 思考?

我可以得到吗?

我需要访问IP和site1.com,并让他们指向不同的目录(不同的项目)

Site1.com

#NameVirtualHost site1.com:80 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/www/site1.com/current/web ServerName site1.com ServerAlias site1.com <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/site1.com/current/web/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/app_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/app_access.log combined </VirtualHost> 

IP地址

 NameVirtualHost 192.168.1.100:80 <VirtualHost 192.168.1.100:80> #<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/www/ip/current/ ServerName 192.168.1.100 ServerAlias 192.168.1.100 <Directory /home/www/ip/current/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/ip_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/ip_access.log combined </VirtualHost> 

更新与解决scheme

Site1.com

 #NameVirtualHost site1.com:80 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/www/site1.com/current/web ServerName site1.com ServerAlias site1.com <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/site1.com/current/web/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/app_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/app_access.log combined </VirtualHost> 

IP地址

 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/www/ip/current/ ServerName 192.168.1.100 #ServerAlias 192.168.1.100 <Directory /home/www/ip/current/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/ip_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/ip_access.log combined </VirtualHost> 

您的VirtualHost指令都需要与NameVirtualHost指令相匹配。 因此,您必须在VirtualHost Name VirtualHost中使用*:80 ,或者在所有地方使用192.168.1.100:80

您也不需要设置与ServerNameServerAlias相同的名称。 ServerAlias除了ServerName以外,还可以指定要分配给该虚拟主机的其他ServerName

将没有ServerName的虚拟主机设置为全部虚拟主机:

 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/www/ip/current/ <Directory> ...