V
V
Vitaly2020-05-05 18:37:39
Nginx
Vitaly, 2020-05-05 18:37:39

How to redirect to the desired route in nginx?

All the best!
Here is part of nginx config

server {
    listen 443 ssl;

    server_name nameone.com;
    server_name nametwo.com;



    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:20m;


    access_log /var/log/nginx/nginx.vhost.access.log;
    error_log /var/log/nginx/nginx.vhost.error.log;

    if ($request_uri = "https://nameone.com"){
        return 301 https://nameone.com/routea;
    }


    location /routea/ {
        proxy_pass http://localhost:8087;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;   
        proxy_cache_bypass $http_upgrade;
    }
}


I'm trying to set it up so that when https://nameone.com is requested , a redirect to https://nameone.com/routea
occurs, but my rule doesn't work :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-05-05
@Lynn

Because there is no host in $request_uri.
That's right

location = / {
    return 301 https://nameone.com/routea/;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question