1

I have a redirect problem with nginx and I really don't know how to do it.

The problem is that I need to redirect all the traffic to a website INCLUDING THE PATH

BASE_URL: https://example.com/auth/

For example if the request is: https://example.com/auth /some/path/

I need it to redirect to: https://newdomain.com /some/path/

In other words, I need to concatenate the part of / some / path / to the new URL.

Here is the part of my code that I have tried

   location  /auth/* {
          proxy_pass https://newdomain.com/$request_uri; 
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $host;
   }

Thanks.

1 Answer 1

1

the issue seems to be the URL handling. You need a small regexp and get the result.

try:

  location  ~ ^/auth/(.*)$  {
      proxy_pass https://newdomain.com/$1; 
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
  }

You can find examples there https://www.liaohuqiu.net/posts/nginx-proxy-pass/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.