产品服务AMH 免费服务器主机面板SSL证书 免费SSL证书申请 担保单 免费安全、零费率交易平台编程助手免费智能写代码、翻译AMYSQL 免费MySQL管理工具

AMH 社区首页

 AMH社区 - 开放自由有价值的社区

[求助帖] nginx通配符能自动反代吗?

coolloyal
铁牌会员
59.00 价值分

coolloyal 发表于 2014-04-13 16:49:04
本帖最后由 coolloyal 于 2014-4-13 21:59 编辑

例如 www.test.com 自动反代到test.xxx.com这样的二级域名上面
www.test1.com反代到test1.xxx.com


server {
listen 80;
server_name ~^(www\.)?(.+)$;
index index.php index.html index.htm;

location / {
default_type text/html;
proxy_cache amproxy;
subs_filter_types text/css text/xml;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://$1.xxx.com;
proxy_set_header Host $1.xxx.com;
proxy_pass http://$1.xxx.com;
proxy_set_header Accept-Encoding "";
}
}

评价: 这个问题有价值吗?  没有 (0分)   有, 感谢 (0分)
2014-04-13 16:49:04 1

Kvm
银牌会员
3872.65 价值分

这样用途??
评价: 这个答复有价值吗?  没有 (0分)   有, 感谢 (0分)
回复  2014-04-13 21:35:45 2

coolloyal
铁牌会员
59.00 价值分

不行吗?这个配置我用了不行。
评价: 这个答复有价值吗?  没有 (0分)   有, 感谢 (0分)
回复  2014-04-13 21:59:14 3

coolloyal
铁牌会员
59.00 价值分

server {
listen 80;
server_name ~^(www\.)?(?<domain>.+)\..+$;
index index.php index.html index.htm;

location / {
default_type text/html;
proxy_cache amproxy;
subs_filter_types text/css text/xml;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://$domain.xxx.com;
proxy_set_header Host $domain.xxx.com;
proxy_pass http://$domain.xxx.com;
proxy_set_header Accept-Encoding "";
}
}


这个配置也不能实现呢
评价: 这个答复有价值吗?  没有 (0分)   有, 感谢 (0分)
回复  2014-04-13 22:44:06 4

amysql
创始人
99532.51 价值分

第一方正常的话匹配到的也是用$2吧。
参考官方文档
http://wiki.nginx.org/HttpCoreModule#server_name

http://amysql.com/bbs/forum.php?mod=viewthread&tid=776

最好可以安装一个echo模块做下输出调试。
评价: 这个答复有价值吗?  没有 (0分)   有, 感谢 (0分)
回复  2014-04-14 17:56:13 5

AMH面板 - 好用高效低占用、安全可靠极稳定

Captain
金牌会员
6928.40 价值分

又见楼主 支持
评价: 这个答复有价值吗?  没有 (0分)   有, 感谢 (0分)
回复  2014-04-16 06:39:57 6
 1  (总1页)
AMH社区列表
用户服务中心