我们的团队最近从一个Apache服务器转移到了nginx,并且遇到了让我们的一个老代理工作的问题。
我们使用Elastic Beanstalk来进行部署,但是我们有一个代理,原因是无法通过不同的path到达EBurl。
这个想法是,我们可以通过代理到ElasticBeanstalk域的内部URL来访问我们的AWS机器。
例:
用户生成一个AWS机器,URL是:
http://my-random-aws-machine-name.us-east-1.elasticbeanstalk.com/
用户使用以下方式testing,而不是使用上面的URL:
http://my-random-aws-machine-name.aws.test-server.ourdomain.com/
换句话说… * .aws.test-server.ourdomain.com – > * .us-east-1.elasticbeanstalk.com
我们如何才能在nginx中工作?
这是旧的Apache代理:
<VirtualHost 5.5.5.5:80> ServerName aws.test-server.ourdomain.com ServerAlias *.aws.test-server.ourdomain.com SetEnvIf Host "(.*?)\.aws\.test-server\.ourdomain\.com.*" proxyHost=$1.us-east-1.elasticbeanstalk.com ProxyPassInterpolateEnv On ProxyPass / http://${proxyHost}/ interpolate ProxyPassReverse / http://${proxyHost}/ interpolate </VirtualHost>
这使我们能够严格使用快捷url。 这也不是redirect – 它将地址栏设置为* .aws.test-server.ourdomain.com。
下面是我们对nginx的一个基本模板,尽pipe它是非常准确的,因为没有其他任何东西能取得任何成功:
http { server { listen 80; server_name ~^(?<subdomain>)\.aws\.test-server\.ourdomain\.com$; location / { proxy_pass http://$subdomain.us-east-1.elasticbeanstalk.com/; } } }
但每次我点击页面,我只是得到我们的根index.html文件。
迷茫和迷茫 – 过去有人曾经做过这样的事情。 先谢谢你!
编辑:
取得了一些进展,它现在在我的本地机器上工作。 这是一个正则expression式的问题,$ subdomainvariables没有被捕获。 但是,当我将更改推送到实际的服务器时仍然有超时问题。 不知道为什么这只是在超时之前无限落后?
server { listen 80; server_name ~^([^\.]+).aws.test-server.ourdomain.com$; location / { proxy_pass http://$1.us-east-1.elasticbeanstalk.com/; } }