![Apache 中的多个域](https://linux22.com/image/576893/Apache%20%E4%B8%AD%E7%9A%84%E5%A4%9A%E4%B8%AA%E5%9F%9F.png)
设置多个域名时遇到困难
当我 sudo a2ensite example2 时,无论 example1 是启用还是禁用,它都不会加载……当然,example1 本身也会被删除。以下是两个文件(example2 基于 example1)
在 sites-available 中我有 example1 文件
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example1.com
ServerAlias example1.com
DocumentRoot /var/www/example1
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example1/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/ubuntu/www/logs/example1/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/ubuntu/www/logs/example1/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
和 example2 文件
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName example2.com
ServerAlias example2.com
DocumentRoot /var/www/example2
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/ubuntu/www/logs/example2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/ubuntu/www/logs/example2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
我有
NameVirtualHost *:80
在 ports.conf 中
我错过了什么?
答案1
你的配置确实太复杂了。首先,看看http://httpd.apache.org/docs/2.0/vhosts/examples.html
然后,将这些文件精简到最低限度。确保激活站点并确保目录存在。这应该可以解决问题。此外,完成所有这些操作后,不要忘记重新加载 apache。