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

Opencart multistore + Nginx + SSL Redirect to WWW Topic is solved

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
4 posts • Page 1 of 1
magzen
Posts: 47
Joined: Sat Sep 05, 2015 6:16 pm

Opencart multistore + Nginx + SSL Redirect to WWW
  • Quote

Post by magzen » Wed Oct 24, 2018 7:04 am

Hello,

I have had a problem with setting up my Opencart mutlistore with 3 domains to redirect to https://www correctly for the past few days but havent managed

Have added following line in domain.com.nginx.txt

return 301 https://$host$request_uri;

but it only redirects http://www to https://www
http:// are redirected to https:// instead of https://www

iam using opencart web template

domain.com.nginx.txt looks like the following

Code: Select all

server {
    listen      37.187.24.2:80;
    server_name b.com www.b.com c.com r.com www.c.com www.r.com;
	return 301 https://$host$request_uri;
    root        /home/admin/web/b.com/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/b.com.log combined;
    access_log  /var/log/nginx/domains/b.com.bytes bytes;
    error_log   /var/log/nginx/domains/b.com.error.log error;
    location / {
        try_files $uri $uri/ @opencart;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9002;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

    location /vstats/ {
        alias   /home/admin/web/b.com/stats/;
        include /home/admin/conf/web/b.com.auth*;
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/admin/web/b.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/admin/conf/web/nginx.b.com.conf*;
}

and domain.com.nginx.ssl.txt

Code: Select all

server {
    listen      37.187.24.2:443;
    server_name b.com www.b.com c.com r.com www.c.com www.r.com;
    root        /home/admin/web/b.com/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/b.com.log combined;
    access_log  /var/log/nginx/domains/b.com.bytes bytes;
    error_log   /var/log/nginx/domains/b.com.error.log error;

    ssl         on;
    ssl_certificate      /home/admin/conf/web/ssl.b.com.pem;
    ssl_certificate_key  /home/admin/conf/web/ssl.b.com.key;

    location / {
        try_files $uri $uri/ @opencart;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9002;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

    location /vstats/ {
        alias   /home/admin/web/b.com/stats/;
        include /home/admin/conf/web/b.com.auth*;
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/admin/web/b.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/admin/conf/web/snginx.b.com.conf*;
}
have tried searching the web for answers but didnt find anything helping my case

can someone please help with this issue so both http and https points to https://www. ?
Last edited by magzen on Tue May 19, 2020 12:20 am, edited 2 times in total.
Top

mehargags
Support team
Posts: 1096
Joined: Sat Sep 06, 2014 9:58 pm
Contact:
Contact mehargags
Website Skype

Os: Debian 8x
Web: apache + nginx
Re: Opencart multistore + Nginx + SSL Redirect to WWW
  • Quote

Post by mehargags » Wed Oct 24, 2018 7:44 am

in your domain's nginx config just put www in front of the redirect directive:

return 301 https://www.$server_name$request_uri;
Top

magzen
Posts: 47
Joined: Sat Sep 05, 2015 6:16 pm

Re: Opencart multistore + Nginx + SSL Redirect to WWW
  • Quote

Post by magzen » Wed Oct 24, 2018 8:08 am

mehargags wrote: ↑
Wed Oct 24, 2018 7:44 am
in your domain's nginx config just put www in front of the redirect directive:

return 301 https://www.$server_name$request_uri;
Thanks for your fast reply, fixed the issue :)
Top

magzen
Posts: 47
Joined: Sat Sep 05, 2015 6:16 pm

Re: Opencart multistore + Nginx + SSL Redirect to WWW
  • Quote

Post by magzen » Tue May 19, 2020 12:48 am

Hello,

This is an old thread created by me, the solution above i wrote 2 years ago that it worked, but it didnt work i was mistaken

I hired at that time someone to fix the redirections for me, he had to separate the multidomains aliases in 3 nginx config files for the redirection to work properly, but at the same time this broke the Vestacp web
control for the domains, since Vestacp works with 1 file when aliases are added, i had to renew letsencrypt using ssh instead.

the following command had some issues return 301 https://www.$server_name$request_uri;

Code: Select all

https://a.com/ would not redirect to https://www.a.com/
https://b.com/ would not redirect to https://www.b.com/
https://c.com/ would not redirect to https://www.c.com/

Code: Select all

http://www.b.com redirects to https://www.a.com/ (main store)
http://www.c.com redirects to https://www.a.com/ (main store)
the only thing that is working correctly with the command https://www.$server_name$request_uri;

Code: Select all

http://www.a.com/ redirects to https://www.a.com/
the guy i hired used the following command return 301 https://www.$host$request_uri; in 3 files that made redirection work properly

using it in 1 file also created issues like

Code: Select all

http://www.a.com redirects to https://www.www.a.com
http://www.b.com redirects to https://www.www.b.com
http://www.c.com redirects to https://www.www.c.com

Code: Select all

https://a.com dont redirect to https://www.a.com
https://b.com dont redirect to https://www.b.com
https://b.com dont redirect to https://www.b.com
the redirection change was made in the domain.com.nginx.conf file not in domain.com.nginx.ssl.conf


Now i have moved to a new server and prefer to use 1 nginx config file for opencart multistore that can redirect all my stores correctly to https://www. would appreaciate if someone have a solution and can help

using apache .htaccess was much easier, but then that option have other issues with performance
Top


Post Reply
  • Print view

4 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