我正在做一个特定的设置,如下所示:
ServerName提供某些内容,并将其他一些ServerName转发给localhost:8080,让nginx完成负载平衡工作。我遇到的问题是,要重定向到nginx的主机名的数量正在快速增长,而且我有一个令人讨厌的vhost列表,这变得很难维护。
因此,问题是:是否有一种方法可以在apache中不使用ServerNames定义默认vhost,并使其重定向所有未匹配任何其他vhost的流量到localhost:8080?
我已经尝试删除了ServerName指令,但问题是,然后ProxyPassReverse将其hostname插入到传出URL中。
目前,我唯一能做的就是将每个vhost中的行数减少到最小,但还是太多了。
这里有一些配置示例:
Nginx:
upstream foo {
server foo1.local:9999 max_fails=3 fail_timeout=30s;
server foo2.local:9999 max_fails=3 fail_timeout=30s;
}
upstream bar {
server bar1.local:8888 max_fails=3 fail_timeout=30s;
server bar2.local:8888 max_fails=3 fail_timeout=30s;
}
server {
listen *:8080;
server_name foo.public.com;
access_log /var/log/nginx/foo.public.com-access.log proxy;
error_log /var/log/nginx/foo.public.com-error.log;
location / {
proxy_pass http://foo/;
include /etc/nginx/proxy_app.conf;
}
}
server {
listen *:8080;
server_name bar.public.com;
access_log /var/log/nginx/bar.public.com-access.log proxy;
error_log /var/log/nginx/bar.public.com-error.log;
location / {
proxy_pass http://bar/;
include /etc/nginx/proxy_app.conf;
}
}阿帕奇:
<VirtualHost *:80>
ServerName foo.public.com
ErrorLog /var/log/httpd/nginx-redirect.sis.service-error.log
CustomLog /var/log/httpd/nginx-redirect.sis.service-access.log combined
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://%{HTTP_HOST}:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName bar.public.com
ErrorLog /var/log/httpd/nginx-redirect.sis.service-error.log
CustomLog /var/log/httpd/nginx-redirect.sis.service-access.log combined
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://%{HTTP_HOST}:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName baz.public.com
DocumentRoot /some/local/path
<Directory "/">
some irrelevant options
</Directory>
</VirtualHost>在本例中,只有两个vhost转发到nginx,但在我的实际设置中,有超过30个!
正如我所说的,我已经尝试使用一个没有ServerName标记的vhost来转发流量,但是我最终在重定向中获得了http://balancer.local/some/path,这显然不起作用。
我还尝试使用单个ServerName和多个ServerAlias,但在这种情况下,ProxyPassReverse总是在响应中使用ServerName。
有什么建议吗?
发布于 2014-03-26 11:04:18
我还尝试使用单个ServerName和多个ServerAlias,但在这种情况下,ProxyPassReverse总是在响应中使用ServerName。
可能您的Apache中有UseCanonicalName On。
尝试在Off中显式地设置它。
https://stackoverflow.com/questions/22639670
复制相似问题