把Nginx放在Heroku的应用程序前,拒绝IP访问

我们在http://random-heroku-app.herokuapp.com上有Heroku应用程序,并且使用HTTPS的访问权限必须仅限于2个IP。 Nginx与它的允许function在这里是完美的。

但是,是否有可能在AWS中部署Nginx并对其进行configuration,使其成为Heroku应用的“前台”?

例如:如果我去http://random-heroku-app.herokuapp.com首先会检查我是否尝试从允许的IP连接,然后代理我到http://random-heroku-app.herokuapp.com

先谢谢你!

当然可以!

你只需要在nginx里面有一个服务器块,那看起来就像这样:

 server { listen 443 ssl; server_name random-heroku-app.herokuapp.com; ssl_certificate .ssl/cert.crt; ssl_certificate_key .ssl/key.key; allow publicip; deny all; location / { proxy_pass https://appip:443; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }