With nginx redirect or rewrite and use proxy_pass

There was here a little problem to redirect using nginx with a certain request to the site. To carry out our mission, I will give an example config:

bash:

  1. server {
  2. listen 80;
  3. server_name www.site.ru site.ru;
  4. reset_timedout_connection on;
  5. location ~* /Service {
  6. proxy_pass http://avia.go2see.ru;
  7. }
  8. location ~* /Service2 {
  9. rewrite ^ http://demo.site.ru/Service2 permanent;
  10. }
  11. location / {
  12. proxy_pass http://www/;
  13. proxy_next_upstream error timeout invalid_header http_500 http_503;
  14. proxy_set_header Host $host;
  15. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  16. proxy_redirect off;
  17. proxy_connect_timeout 120;
  18. }
  19. }

Unlike rewrite of proxy_pass is that the redirect will look “open”. Ie Page processed automatically forwarded to the new address.

In the case of a leave request proxy_pass transparent”, ie user does not even realize that there was a request for a new url address.

Leave a Reply

Your email address will not be published. Required fields are marked *