πŸ‘½ 301 redirect coming from page that does not exist!

I put it like this!

server {
listen 80;
        server_mysite.com.br;
        return 301 https://www.mysite.com.br$request_uri;
}
server {
listen 80;
       server_name www.mysite.com.br;
       return 301 https://www.mysite.com.br$request_uri;
}

But the error in the test.

nginx: [emerg] unknown directive β€œserver_mysite.com.br” in /etc/nginx/conf.d/force-ssl-mysite.com.br.conf:3 nginx: configuration file /etc/nginx/nginx.conf test failed

@virtubox

In this way it seems to work perfectly.

server {
listen 80;
       server_name www.mysite.com.br mysite.com.br;
       return 301 https://www.mysite.com.br$request_uri;
}

~# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

@virtubox

I noticed that now this urls (https://mysite.com.br/) is not redirecting to www

Have you applied the configuration with service nginx reload ?

yes

@virtubox

Showing this in the redirection test. For this url

In this case try the global :

server {
        server_name "~^(?!www\.).*" ;
        return 301 $scheme://www.$host$request_uri;
}

You mean to put exactly like that on the block.

No create a file www-redirect.conf in /etc/nginx/conf.d with this content :

server {
        server_name "~^(?!www\.).*" ;
        return 301 $scheme://www.$host$request_uri;
}

[quote=β€œvirtubox, post:23, topic:9334”] No create a file www-redirect.conf in /etc/nginx/conf.d with this content :

disable all plugins which can impact the redirection : WP-Rocket, Wordfence, HideMyWP and any other plugin like that

@virtubox

All related plugins have been shut down. And cloudflare paused. But url still does not redirect.

Website do not work anymore but I was redirected to www.

It’s working so I went to try another model.

@virtubox But one of the urls does not redirect.

@virtubox

When I put it like this it does not redirect the url https://chefclub.com.br/ to www.

I saw that several people could not do it the way it shows in the tutorial. He seems to be wrong about what I saw or obsolete according to the comments.

In this case do like that :

server {
    server_name  chefclub.com.br;
    return       301 https://www.example.org$request_uri;
    include /var/www/chefclub.com.br/conf/nginx/*.conf;
}

server { server_name www.chefclub.com.br; access_log /var/log/nginx/chefclub.com.br.access.log rt_cache; error_log /var/log/nginx/chefclub.com.br.error.log;

root /var/www/chefclub.com.br/htdocs;

index index.php index.html index.htm;

include common/php.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/chefclub.com.br/conf/nginx/*.conf;

}


But "rewrite" is not a correct directive with nginx : 
http://nginx.org/en/docs/http/converting_rewrite_rules.html

Strange he does not accept

return 301 https://www.example.org$request_uri;

have you set a server directive in another one ?

It’s not like it’s always been