Why when I click login or logout button alwayd redirect to original website/proxied website

server {
listen 80;
server_name abcd.com;
return 301 https://$server_name$request_uri;


server { listen 443 ssl; listen [::]:443 ssl;

ssl_certificate /etc/ssl/doremi/abcd.crt;
ssl_certificate_key /etc/ssl/doremi/private.key;

server_name abcd.com;

location / {
proxy_pass http://xyz.vip;
proxy_set_header Accept-Encoding "";
sub_filter 'http://xyz.vip' 'https://abcd.com';
sub_filter 'http://xyz.vip/dashboard' 'https://abcd.com/dashboard';
sub_filter_once off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


Whenever i click login button at abcd.com always goes to xyz.vip , thank you for the help

So I tried to curl abcd.com and this some result below, still confused to make xyz.vip become abcd.com

curl -vv http://abcd.com/main

< HTTP/1.1 302 Found

< Server: nginx/1.14.0 (Ubuntu)

< Date: Wed, 30 Dec 2020 05:48:58 GMT

< Content-Type: text/html; charset=UTF-8

< Transfer-Encoding: chunked

< Connection: keep-alive

< location: http://xyz.vip

    <meta charset="UTF-8" />
    <meta http-equiv="refresh" content="0;url='http://xyz.vip'" />

    <title>Redirecting to http://xyz.vip</title>
    Redirecting to <a href="http://xyz.vip">http://xyz.vip</a>.

Can you try a couple things ? add this in your location

proxy_set_header Host $host;


return 301 https://abcd$request_uri;

instead of https://$server_name$request_uri;

I'm not using sub_filter options and mine is working fine.

  • Still not work bro, The problem is just happen to some website. – Sinauwae Dec 30 '20 at 0:53
  • is the location field bothering you, or is the redirect not working at all ? if it's the first one, try adding this directive to your location under proxy_pass : proxy_redirect off; or proxy_redirect default; – MeMow Dec 30 '20 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.