Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Modification & Patches
  • Search

Forward ip to domain - SSL

Section with modification and patches for Vesta
Post Reply
  • Print view
Advanced search
20 posts
  • 1
  • 2
  • Next
emardotcom
Posts: 54
Joined: Wed Dec 11, 2013 9:05 pm

Forward ip to domain - SSL
  • Quote

Post by emardotcom » Wed Dec 11, 2013 9:13 pm

Hello I updated VestaCp with new ssl certificates but they don't work with my ip only with my domain. So I have been playing with everything to make VestaCp rewrite or forward to my domain but I cant find a way to do it. I tried adding .htaccess and editing the nginx file but nothing seams to work can someone please help me with this?


aaa.bbb.ccc.ddd -> https://www.example.com
Top

emardotcom
Posts: 54
Joined: Wed Dec 11, 2013 9:05 pm

Re: Forward ip to domain - SSL
  • Quote

Post by emardotcom » Thu Dec 12, 2013 2:35 am

This seems to work in /usr/local/vesta/web/index.php

Code: Select all

$redirect = 'www.domain.com:'.$_SERVER['SERVER_PORT'];
if ($_SERVER['HTTP_HOST'] != $redirect) {
	header("Location: https://$redirect/");
	exit;
}
The only issue is you will have to do this for every /dir/ I cant find where to edit this globally.
.htaccess doesn't work I tried editing /usr/local/vesta/nginx/conf/nginx.conf but when I do a rewrite in there it doesn't work.
Top

emardotcom
Posts: 54
Joined: Wed Dec 11, 2013 9:05 pm

Re: Forward ip to domain - SSL
  • Quote

Post by emardotcom » Thu Dec 12, 2013 4:54 am

Ok so apparently I wasn't writing the correct nginx code.
All you have to do is edit the above mentioned nginx.conf

if ($http_host !~* ^(www\.)?example.com:8083$) {
rewrite ^(.*)$ https://www.example.com:8083$1 permanent;
}

Code: Select all

    # Vhost
    server {
        listen          8083;
        server_name     _;
        root            /usr/local/vesta/web;
        charset         utf-8;

        ssl                  on;
        ssl_certificate      /usr/local/vesta/ssl/certificate.crt;
        ssl_certificate_key  /usr/local/vesta/ssl/certificate.key;
        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        error_page      404     /error/index.html;
        error_page      403     /error/index.html;
        error_page      500     /error/index.html;
        
		if ($http_host !~*  ^(www\.)?example.com:8083$) {
			rewrite ^(.*)$ https://www.example.com:8083$1 permanent;
		}

        location / {
            expires max;
            index   index.php;
        }
...
that will fix the issue :)
Top

DFS
Posts: 73
Joined: Tue Nov 12, 2013 4:32 pm

Re: Forward ip to domain - SSL
  • Quote

Post by DFS » Thu Dec 19, 2013 4:10 pm

dont use IF
http://wiki.nginx.org/IfIsEvil

use this

Code: Select all

server {
    listen       8083 default_server;
    server_name  _;
    return 301 https://example.com$request_uri;
}

server {
    listen       8083;
    server_name  example.com;
    
    root            /usr/local/vesta/web;
    charset         utf-8;

    ssl                  on;
    ssl_certificate      /usr/local/vesta/ssl/certificate.crt;
    ssl_certificate_key  /usr/local/vesta/ssl/certificate.key;
    ssl_session_cache    shared:SSL:10m;
    ssl_session_timeout  10m;
...
Top

emardotcom
Posts: 54
Joined: Wed Dec 11, 2013 9:05 pm

Re: Forward ip to domain - SSL
  • Quote

Post by emardotcom » Sun Feb 02, 2014 8:42 pm

Thanks for your suggestion i went ahead and used the following:

Code: Select all

    server {
        listen          8083;
        server_name     _;
        root            /usr/local/vesta/web;
        charset         utf-8;

        ssl                  on;
        ssl_certificate      /usr/local/vesta/ssl/certificate.crt;
        ssl_certificate_key  /usr/local/vesta/ssl/certificate.key;
        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        error_page      404     /error/index.html;
        error_page      403     /error/index.html;
        error_page      500     /error/index.html;
        error_page		497		https://$host:$server_port$request_uri;
        
		if ($host !~*  ^www(.*)) {
			return		301		https://www.example.com:$server_port$request_uri;
		}


        location / {
            expires max;
            index   index.php;
        }
This makes VestaCP use HTTPS, adds WWW and forwards direct ip to your domain.
Top

emardotcom
Posts: 54
Joined: Wed Dec 11, 2013 9:05 pm

Re: Forward ip to domain - SSL
  • Quote

Post by emardotcom » Mon Feb 03, 2014 3:55 am

add the following after the above if question to force only one domain for vestacp:

Code: Select all

		if ($host !~*  ^www\.example\.com$) {
			return		301		https://www.example.com:$server_port$request_uri;
		}
Top

iamkingsleyf
Posts: 30
Joined: Sun Nov 23, 2014 4:41 am

Re: Forward ip to domain - SSL
  • Quote

Post by iamkingsleyf » Thu Jan 01, 2015 8:53 pm

Not working for me...
This webpage is not available
Top

donkfather
Posts: 8
Joined: Fri Apr 03, 2015 10:18 pm

Re: Forward ip to domain - SSL
  • Quote

Post by donkfather » Mon May 04, 2015 8:44 am

.htaccess worked for me :) i will later post the exact code :)
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Forward ip to domain - SSL
  • Quote

Post by skurudo » Tue May 05, 2015 10:10 am

donkfather wrote:.htaccess worked for me :) i will later post the exact code :)
Something like this, I think.

Code: Select all

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Top

hafeezksa
Posts: 81
Joined: Mon Apr 27, 2015 5:45 pm
Contact:
Contact hafeezksa
Website

Re: Forward ip to domain - SSL
  • Quote

Post by hafeezksa » Tue May 12, 2015 6:45 pm

skurudo wrote:
donkfather wrote:.htaccess worked for me :) i will later post the exact code :)
Something like this, I think.

Code: Select all

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Where to keep this .htaccess file ?
Top


Post Reply
  • Print view

20 posts
  • 1
  • 2
  • Next

Return to “Modification & Patches”



  • 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