我有以下配置,Varnish 充当面向外部的端点 (NGINX) 和 Apache 之间的缓存。
+-------+ +-------+ +------+
| NGINX | +---> |Varnish| +---> |Apache|
+-------+ +-------+ +------+
当我从浏览器调用它时,我无法匹配我的 Apache VirtualHost 配置。我的(单个)VirtualHost 的配置如下所示:
<VirtualHost *:80>
ServerName fabrikam.com
ServerAlias fabrikam.com
ServerAdmin myemailaddress
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access-mycustomlog.log combined
</VirtualHost>
这是 Apache 版本:
root@localhost:/etc/apache2# apache2 -v
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jan 14 2016 17:45:23
症状
当我访问https://fabrikam.com
时,它没有给我文件夹的根/var/www/html
目录。相反,它尝试访问 的根目录/var/www
,并且因为我禁用mod_index
了 ,它给了我一个 HTTP 404 Not Found 错误。
关于如何让这个 VirtualHost 配置正确“匹配”的任何想法?当我访问 fabrikam.com 时,它应该转到/var/www/html
文件夹,而不是文件/var/www
中apache2.conf
。
编辑
这是来自的输出apachectl -S
root@localhost:/etc/apache2# apachectl -S
VirtualHost configuration:
*:80 fabrikam.com (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
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
Group: name="www-data" id=33
NGINX 配置
### Rewrite non-HTTPS URLs to HTTPS
server {
listen 80;
server_name fabrikam.com;
rewrite ^ https://$server_name$request_uri?;
}
server {
listen 443 ssl;
server_name fabrikam.com;
ssl_certificate /etc/letsencrypt/live/fabrikam.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/fabrikam.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:6081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
}
确保 Apache 在正确的实例/端口上命中,并且 Host 标头通过中间层正确转发。