Page 1 of 2
Forward ip to domain - SSL
Posted: Wed Dec 11, 2013 9:13 pm
by emardotcom
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
Re: Forward ip to domain - SSL
Posted: Thu Dec 12, 2013 2:35 am
by emardotcom
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.
Re: Forward ip to domain - SSL
Posted: Thu Dec 12, 2013 4:54 am
by emardotcom
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 :)
Re: Forward ip to domain - SSL
Posted: Thu Dec 19, 2013 4:10 pm
by DFS
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;
...
Re: Forward ip to domain - SSL
Posted: Sun Feb 02, 2014 8:42 pm
by emardotcom
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.
Re: Forward ip to domain - SSL
Posted: Mon Feb 03, 2014 3:55 am
by emardotcom
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;
}
Re: Forward ip to domain - SSL
Posted: Thu Jan 01, 2015 8:53 pm
by iamkingsleyf
Not working for me...
This webpage is not available
Re: Forward ip to domain - SSL
Posted: Mon May 04, 2015 8:44 am
by donkfather
.htaccess worked for me :) i will later post the exact code :)
Re: Forward ip to domain - SSL
Posted: Tue May 05, 2015 10:10 am
by skurudo
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]
Re: Forward ip to domain - SSL
Posted: Tue May 12, 2015 6:45 pm
by hafeezksa
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 ?