Nginx通配符代理,将子域传递给服务器(上游代理)
我希望能够将子域.domain.com传递给.domain.com apache服务器,并同时提供子域信息 我想为域创建一个nginx缓存,就像通配符一样,但是将子域传递到目标(还有apachewitch通配符)。到目前为止,我通过proxy\u set\u header Host$Host传递信息但我希望在apache服务器上有子域请求Nginx通配符代理,将子域传递给服务器(上游代理),nginx,wildcard,wildcard-subdomain,Nginx,Wildcard,Wildcard Subdomain,我希望能够将子域.domain.com传递给.domain.com apache服务器,并同时提供子域信息 我想为域创建一个nginx缓存,就像通配符一样,但是将子域传递到目标(还有apachewitch通配符)。到目前为止,我通过proxy\u set\u header Host$Host传递信息但我希望在apache服务器上有子域请求 upstream domain.com { server 172.1.1.1:80 weight=50 fail_timeout=30s; }
upstream domain.com {
server 172.1.1.1:80 weight=50 fail_timeout=30s;
}
server {
server_name *.domain.com;
location / {
proxy_pass http://domain.com;
#proxy_pass $request;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
location ~* ^.+. (jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf)$ {
proxy_pass http://topmanagergame.com;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache my-cache;
proxy_cache_valid 200 302 30m;
proxy_cache_valid 404 1m;
}
access_log /var/log/nginx/domain.com.log main;
error_log off;
}
你认为我可以用上游的代理通行证吗
Nginx (*wildcard_domain.com) --(cache)--> Apache (*wildcard_domain.com)
Nginx (anything.domain.com) --(cache)--> Apache (anything.domain.com)
上游字符串{
ServerDomain2.com:80权重=50失败\超时=30s;
}
服务器{
听80;
服务器名称*.domain.com;
服务器名称~^(?.+)\.domain\.com$;
地点/{
代理通行证http://somestring;
代理集头主机$subdomain.domain2.com;
}
}
所以我试图找到这个问题的答案,并一直在寻找这篇文章。但我认为dmytrivv的答案已经过时了。在我们的场景中,我们有通配符域(例如.*.mydomain.com)和自定义域(例如fullycustomdomain.com)。但您可以通过使用proxy_set_header Host$Host解决这两个问题;在你的聆听结束时有默认值
upstream qaweb {
# Servers in the web farm
server ip-notreal-name.ec2.internal:80;
}
server {
listen 443 ssl default;
ssl_certificate certs/mydomain.com.crt;
ssl_certificate_key certs/mydomain.com.key;
# Support for wildcard domains
server_name admin.mydomain.com *.mydomain.com "";
location / {
# Turn off access logging so we don't fill the hardrive
access_log off;
proxy_pass http://qaweb;
proxy_set_header Host $host;
# So that the correct IP shows up in the log once libapache2-mod-rpaf is installed
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
注意,我们还将其用作TLS终止代理
你也可以在这里找到更多关于如何使用proxy_pass的例子你知道这一点吗?如果有关于这个答案的解释就好了。只使用代码作为答案,虽然可能是准确的,但并没有给出任何关于其工作原理的信息。知道某些东西为什么起作用远比知道什么起作用更有价值。
upstream qaweb {
# Servers in the web farm
server ip-notreal-name.ec2.internal:80;
}
server {
listen 443 ssl default;
ssl_certificate certs/mydomain.com.crt;
ssl_certificate_key certs/mydomain.com.key;
# Support for wildcard domains
server_name admin.mydomain.com *.mydomain.com "";
location / {
# Turn off access logging so we don't fill the hardrive
access_log off;
proxy_pass http://qaweb;
proxy_set_header Host $host;
# So that the correct IP shows up in the log once libapache2-mod-rpaf is installed
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}