0
Voltooid

Redirect www to non-www

Thibaut 10 jaar geleden bijgewerkt 10 jaar geleden 8
Hello,

I'm trying to do a www to non-www redirect for one of my websites but it looks like everything I try fails. This is what I'm using:
server {
	server_name	www.example.com;
	return 301	http://example.com$request_uri;
}

I then get the following error:
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/examplecom.conf:16
nginx: configuration file /etc/nginx/nginx.conf test failed

Am I doing something wrong?

Antwoord

Antwoord
Voltooid
You can't insert server{} sections into another server{}. Put your snippet into /etc/nginx.custom.d/yourconfig.conf and restart NGINX.
GOED, IK BEN TEVREDEN
Satisfaction mark by Thibaut 10 jaar geleden
Antwoord
Voltooid
You can't insert server{} sections into another server{}. Put your snippet into /etc/nginx.custom.d/yourconfig.conf and restart NGINX.
That's a file I need to create manually or there is a section of the website panel where I can put that code? Is it in "Content > Custom configuration"?
Currently you have to add it manually, but a GUI editor will be added soon.
Understood. So I have to add "server" directives in the /etc/nginx.custom.d/yourconfig.conf but the other "location" directives can stay in "Advanced > Custom configuration"? It that correct?
Yes, everything that isn't server {} goes to GUI. All files in /etc/nginx.custom.d get included into NGINX's root http {} section.
It seems it works but now I have an error in NGINX config test, for each domain I created a custom config file:

nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
+2
Check out http://stackoverflow.com/questions/11426087/nginx-error-conflicting-server-name-ignored 
It's now possible to set server level custom configurations from the GUI. Awesome, thanks!