我的域名example123.com
指向我的 apache 服务器。
我有一个/etc/apache2/sites-available/example123.com.conf
文件
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin [email protected]
ServerName example123.com
ServerAlias www.example123.com
#DocumentRoot /var/www/html
DocumentRoot /var/www/example123.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example123.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
我已经激活了该网站a2ensite example123.com.conf
直到今天早上,该网站都运行良好。我做了几件事。我启用了 Apache Mods 过期和标头
a2enmod expires
,然后a2enmod headers
并且我允许缓存插件 (wordpress) 写入我网站根文件夹中的 .htaccess 文件。此后,我已删除该 .htaccess 文件。
所以我遇到的问题是,当我到达example123.com
它时,它会转到/var/www
并显示目录树,而不是显示网站/var/www/example123.com
apache2ctl -S
节目
VirtualHost configuration:
*:80 is a NameVirtualHost
default server example123.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost example123.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost example123.com (/etc/apache2/sites-enabled/example123.com.conf:1)
alias www.example123.com
port 80 namevhost anothersite123.cc (/etc/apache2/sites-enabled/anothersite123.cc.conf:1)
alias www.anothersite123.cc
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
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
我可以通过在 000-default.conf 中设置 ServerName 来修复该问题
我将服务器名称设置为我的服务器的 IP 地址。
不太清楚这为什么有效。