Apache Virtualhost 仅显示默认页面

Apache Virtualhost 仅显示默认页面

我已经为 Apache Virtualhost 烦恼了一天。我想用一个 IP 运行 2 个网站。

当我在 URL 栏中输入地址(域 1 或域 2)时,它总是只显示默认页面(即域 1)。

任何帮助都将不胜感激...

我的配置:

/var/www/html:

域名1/public_html/index.html

域名2/public_html/index.html

在/etc/apache2/站点已启用:

│ │ 域1.conf -> ../sites-available/域1.conf

└── domain2.conf -> ../sites-available/domain2.conf

域2.conf:

<VirtualHost *:80>

    ServerName www.domain1.tk
    ServerAlias domain1.tk
    DocumentRoot /var/www/html/domain1/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

域2.conf:

<VirtualHost *:80>

    ServerName domain2.tk
    ServerAlias www.domain2.tk
    DocumentRoot /var/www/html/domain2/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Apache2.conf:

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On

MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

答案1

当我查找您的域名时,我得到了 2 个不同的 IP 地址。在这种情况下,您的配置需要如下所示:

# This is the "main" server running on IP_ADDRESS_OF_DOMAIN_tsk-run.tk
ServerAdmin [email protected]
ServerName tsk-run.tk
ServerAlias www.tsk-run.tk
DocumentRoot /var/www/html/tsk-run/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<VirtualHost IP_ADDRESS_OF_DOMAIN_tsk-test.tk>
    ServerAdmin [email protected]
    ServerName tsk-test.tk
    ServerAlias www.tsk-test.tk
    DocumentRoot /var/www/html/tsk-test/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

替换IP_ADDRESS_OF_DOMAIN_tsk-test.tk为此域的 IP 地址。

Apache 文档部分Name-based hosts on more than one IP address以了解更多详细信息。

相关内容