Page 1 of 2
cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 7:21 pm
by heihachi88
Putting the code in this place: /usr/local/vesta/nginx/conf/nginx.conf
Code: Select all
http {
server {
server_name “~^www\.(.*)$” ;
return 301 $scheme://$1$request_uri;
}
}
Then: service nginx restart
Visitng mysite.com - ok, but when i visit
www.mysite.com it doesn't redirects me to mysite.com
What's wrong?
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 7:42 pm
by jarland
Are you using nginx to serve the page completely or as a reverse proxy to Apache?
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 7:47 pm
by heihachi88
jarland wrote:Are you using nginx to serve the page completely or as a reverse proxy to Apache?
Using it as default, probably as reverse proxy but im not sure first time using nginx. How to check it? :)
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 7:49 pm
by jarland
In your public_html folder make a .htaccess file and include these contents. Replace domain.com with your domain, make sure to leave the \ in there.
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:01 pm
by heihachi88
jarland wrote:In your public_html folder make a .htaccess file and include these contents. Replace domain.com with your domain, make sure to leave the \ in there.
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
Still not working :( When i was creating a domain name it had Alias option and it was
http://www.domain.com i have tried to delete it but no success. And when nginx is a reverse proxy with apace - htaccess files should work?
UPDATE, sorry it works now misspelled one sign.
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:07 pm
by jarland
Yeah I use htaccess pretty heavily. I suppose you could always do it the easy way, the way I do it. I just make www a CNAME pointing to my domain. Like this:
www 14400 IN CNAME jarland.me
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:14 pm
by heihachi88
jarland wrote:Yeah I use htaccess pretty heavily. I suppose you could always do it the easy way, the way I do it. I just make www a CNAME pointing to my domain. Like this:
www 14400 IN CNAME jarland.me
Thanks will try that :) When nginx is a reverse proxy - htaccess works only for redirects? Can i set max_upload_size for each site individually? Or it's impossible because of nginx?
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:17 pm
by jarland
heihachi88 wrote:jarland wrote:Yeah I use htaccess pretty heavily. I suppose you could always do it the easy way, the way I do it. I just make www a CNAME pointing to my domain. Like this:
www 14400 IN CNAME jarland.me
Thanks will try that :) When nginx is a reverse proxy - htaccess works only for redirects? Can i set max_upload_size for each site individually? Or it's impossible because of nginx?
With nginx as reverse proxy, as is the default setting, you can make full use of Apache .htaccess files so long as you're using code that corresponds to an available Apache module. The most effective configuration, in my opinion, is to have Apache set to hosting and nginx set to caching. All Apache code is interpreted by Apache, nginx is just caching some stuff to speed up the process, but it passes everything to Apache as necessary.
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:23 pm
by heihachi88
jarland wrote:heihachi88 wrote:jarland wrote:Yeah I use htaccess pretty heavily. I suppose you could always do it the easy way, the way I do it. I just make www a CNAME pointing to my domain. Like this:
www 14400 IN CNAME jarland.me
Thanks will try that :) When nginx is a reverse proxy - htaccess works only for redirects? Can i set max_upload_size for each site individually? Or it's impossible because of nginx?
With nginx as reverse proxy, as is the default setting, you can make full use of Apache .htaccess files so long as you're using code that corresponds to an available Apache module. The most effective configuration, in my opinion, is to have Apache set to hosting and nginx set to caching. All Apache code is interpreted by Apache, nginx is just caching some stuff to speed up the process, but it passes everything to Apache as necessary.
So you advice to set apache to hosting and nginx to caching?
Nice thing, i didn't know that i can make a full use of htaccess with nginx as reverse proxy :)
Also can you enlighten me about PECL uploadprogress with such combination? Is there any possibilities to see an upload progress?
Re: cannot make redirect from www to non-www
Posted: Fri Jan 17, 2014 8:44 pm
by jarland
heihachi88 wrote:
Also can you enlighten me about PECL uploadprogress with such combination? Is there any possibilities to see an upload progress?
You can try running "pecl install uploadprogress" but you might need the PHP development package. On CentOS, "yum install php-devel" or on Debian/Ubuntu "apt-get install php-dev" (or maybe php5-dev). No luck for me installing php-devel on CentOS 6.5 at the moment after a stock Vesta install. Dependency issues.