我有以下配置,其中 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;
}
}
答案1
确保 Apache 命中正确的实例/端口,并且主机头正确通过中间层转发。