Score:0

nginx: [warn] server name has suspicious symbols with long domain redirect

co flag

What is the best way in Nginx to redirect two Long domains URLS, I would like to configure a redirect between two domains like this:

I'm sure this has been asked before, but I can't find a solution that works.

original link:

https://qwerty.test.com/education/7/abc-science

New link

https://www.test.com/education/7/abc-science

I have tried this :

server {
    listen 80;
    listen 443 ssl;
    server_name qwerty.test.com/education/7/abc-scienc;
    return 301 $scheme://www.test.com/education/7/abc-science$request_uri;
}

Still receive some errors

nginx: [warn] server name "education/7/abc-scienc
" has suspicious symbols in /etc/nginx/conf.d/redirect.conf:9

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

duplicate question as : https://stackoverflow.com/questions/74101316/long-url-diffrent-domain-redirect-nginx-issue

do these changes work for me :

server {
    listen 80;
    server_name www.test.com;
    #old url
    location /education/7/abc-science {
        # Unique handler for the URL you want to redirect.
        # new url
        return 301 $scheme://www.test.com/education/7/abc-science;
    }
}

or do I need to add $request_uri; inside the location block

do I need to use this way to redirect from my old URL to the new one?

location = /content/unique-page-name {
  return 301 /new-name/unique-page-name;
}

Can anyone help me with this? What is wrong here?

Any help is appreciated! thanks!

Ginnungagap avatar
gu flag
Don't cross-post questions, if it belongs on SF ask it here, it it doesn't ask it on SO ; not both.
Score:0
us flag

nginx documentation states that server_name is the virtual server name (domain name) of the virtual host.

The documentation also explains what kind of input is allowed there.

You are trying to add a URL instead of domain, that is why the configuration is invalid.

You need to add a location block for the URI part of the URL.

Santosh Baruah avatar
co flag
ok, could you pl describe a bit with an example from my case?
Lex Li avatar
vn flag
@SantoshBaruah a search engine can return you millions of examples if the key words are "nginx" "config" "redirect" "example".
Santosh Baruah avatar
co flag
Thanks , do I need to add $request_uri; in the location, block to redirect to my old URL to the new Url ?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.