Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

cannot make redirect from www to non-www

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
11 posts
  • 1
  • 2
  • Next
heihachi88
Posts: 258
Joined: Fri Jan 10, 2014 7:34 pm

cannot make redirect from www to non-www
  • Quote

Post by heihachi88 » Fri Jan 17, 2014 7:21 pm

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?
Top

jarland
Posts: 28
Joined: Sat Dec 07, 2013 10:40 pm
Contact:
Contact jarland
Website

Re: cannot make redirect from www to non-www
  • Quote

Post by jarland » Fri Jan 17, 2014 7:42 pm

Are you using nginx to serve the page completely or as a reverse proxy to Apache?
Top

heihachi88
Posts: 258
Joined: Fri Jan 10, 2014 7:34 pm

Re: cannot make redirect from www to non-www
  • Quote

Post by heihachi88 » Fri Jan 17, 2014 7:47 pm

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? :)
Top

jarland
Posts: 28
Joined: Sat Dec 07, 2013 10:40 pm
Contact:
Contact jarland
Website

Re: cannot make redirect from www to non-www
  • Quote

Post by jarland » Fri Jan 17, 2014 7:49 pm

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]
Top

heihachi88
Posts: 258
Joined: Fri Jan 10, 2014 7:34 pm

Re: cannot make redirect from www to non-www
  • Quote

Post by heihachi88 » Fri Jan 17, 2014 8:01 pm

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.
Last edited by heihachi88 on Fri Jan 17, 2014 8:09 pm, edited 1 time in total.
Top

jarland
Posts: 28
Joined: Sat Dec 07, 2013 10:40 pm
Contact:
Contact jarland
Website

Re: cannot make redirect from www to non-www
  • Quote

Post by jarland » Fri Jan 17, 2014 8:07 pm

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
Top

heihachi88
Posts: 258
Joined: Fri Jan 10, 2014 7:34 pm

Re: cannot make redirect from www to non-www
  • Quote

Post by heihachi88 » Fri Jan 17, 2014 8:14 pm

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?
Top

jarland
Posts: 28
Joined: Sat Dec 07, 2013 10:40 pm
Contact:
Contact jarland
Website

Re: cannot make redirect from www to non-www
  • Quote

Post by jarland » Fri Jan 17, 2014 8:17 pm

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.
Top

heihachi88
Posts: 258
Joined: Fri Jan 10, 2014 7:34 pm

Re: cannot make redirect from www to non-www
  • Quote

Post by heihachi88 » Fri Jan 17, 2014 8:23 pm

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?
Top

jarland
Posts: 28
Joined: Sat Dec 07, 2013 10:40 pm
Contact:
Contact jarland
Website

Re: cannot make redirect from www to non-www
  • Quote

Post by jarland » Fri Jan 17, 2014 8:44 pm

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.
Top


Post Reply
  • Print view

11 posts
  • 1
  • 2
  • Next

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

cron

Login  •  Register

I forgot my password