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

http (www or non-www) to https non-www on VPS Debian 9 server for all sites

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
3 posts • Page 1 of 1
lotnomore
Posts: 20
Joined: Sun Apr 28, 2019 7:00 pm
Contact:
Contact lotnomore
Website

Os: Debian 8x
Web: apache + nginx
http (www or non-www) to https non-www on VPS Debian 9 server for all sites
  • Quote

Post by lotnomore » Tue May 07, 2019 10:08 pm

I just set up a VPS server from Hostwinds running Debian 9 and Vesta. Have spent days trying to make sure all sites with SSL certificates load this way:

https://anydomain.com

Since I have more than 50 sites on the server and trying to test on the .htaccess file in each domain's public_html folder is a pain in the neck and I also get the "too many redirects" error. I wonder if there is a better and easy way.

I have tried with this one:
https://www.digitalocean.com/community/ ... ntu-14-04/
but that is for apache server, not for the nginx server. So after implementing that by adding the following
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
in the .htaccess file in the /var/www/html folder, I got this after typing this command # curl -I http://www.hanzicode.com
HTTP/1.1 302 Found
Server: nginx
Date: Tue, 07 May 2019 22:03:30 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 205
Connection: keep-alive
Keep-Alive: timeout=60
Location: http://hanzicode.com/
So it works in stripping off www in URL, but not in redirecting to https

I found this
https://www.digitalocean.com/community/ ... n-on-nginx

And everestmx replied this on August 9, 2014:
# host_without_www
if ( $host ~* ^www\.(?<nowww>.*)$ ) {
rewrite .* $scheme://$nowww$request_uri permanent;
}
# host_with_www
if ( $host ~* ^(?!www\.) ) {
rewrite .* $scheme://www.$host$request_uri permanent;
}
This seems to be the global solution for all sites, but which file I should put this code in?
Last edited by lotnomore on Wed May 08, 2019 12:43 am, edited 1 time in total.
Top

kenneth
Posts: 18
Joined: Wed Sep 16, 2015 8:03 pm

Os: Debian 8x
Web: apache + nginx
Re: http (www or non-www) to https non-www on VPS Debian 9 server for all sites
  • Quote

Post by kenneth » Tue May 07, 2019 11:06 pm

Try this one

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Top

lotnomore
Posts: 20
Joined: Sun Apr 28, 2019 7:00 pm
Contact:
Contact lotnomore
Website

Os: Debian 8x
Web: apache + nginx
Re: http (www or non-www) to https non-www on VPS Debian 9 server for all sites
  • Quote

Post by lotnomore » Tue May 07, 2019 11:30 pm

kenneth wrote: ↑
Tue May 07, 2019 11:06 pm
Try this one

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Tried that. No luck, the same response for command

Code: Select all

curl -I http://www.hanzicode.com
HTTP/1.1 302 Found
Server: nginx
Date: Tue, 07 May 2019 23:27:46 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 205
Connection: keep-alive
Keep-Alive: timeout=60
Location: http://hanzicode.com/
Top


Post Reply
  • Print view

3 posts • Page 1 of 1

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
 

 

Login  •  Register

I forgot my password