I've looked at many SE threads and done various google searches and can't figure out why i can't redirect www.mysite.com to mysite.com on my nginx server.
The 1st server block does the http://mysite.info -> https://mysite.info redirect as you'd expect. So i'm not sure why the 2nd server block isn't doing the same for the www.mysite.info -> mysite.info.
Here's the relevant part of my nginx.conf file:
server {
server_name mysite.info;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
server_name www.mysite.info;
rewrite ^ https://mysite.info$request_uri? permanent;
}
server {
listen 443;
ssl on;
server_name mysite.info;
# other directives, handling PHP, etc.
}
Any thoughts on what's going wrong?
return 301instead ofrewrite. – tacotuesday Aug 27 '12 at 23:38return 301given my 3server{}blocks? I've just tried a couple things but get this error:invalid number of arguments in "return" directivewhen I try to restart my server. – tim peterson Aug 28 '12 at 00:01serverblocks? – Michael Hampton Aug 28 '12 at 00:02sudo apt-get install nginx /phpon my ubuntu machine and now here I am, are there other files I need to look at? – tim peterson Aug 28 '12 at 00:04http{}block that were there by default:include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;. Should I comment these out? – tim peterson Aug 28 '12 at 00:06