Page 1 of 1

Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Fri Oct 02, 2015 6:32 pm
by weirdaljr
Right now I run one site on Vesta and it has SSL on it. Currently by default when you go to http://111.111.111.111 it shows the "default.domain - Powered by VESTA" default page for a new site. I just want the http://111.111.111.111 to redirect to http://domain.com or https://domain.com as http://domain.com already goes to https://domain.com.

Which conf is best to put this in and what method?

Re: Recommended way to redirect server IP to Domain?

Posted: Mon Oct 05, 2015 8:47 pm
by weirdaljr
Has anyone been able to do this with Vesta?

Re: Recommended way to redirect server IP to Domain?

Posted: Tue Oct 06, 2015 1:04 am
by weirdaljr
With my 1 ip server I was able to figure out how to do it by editing the one nginx conf below. This worked for me on a 1 IP VPS running Ubuntu with default templates:

/etc/nginx/conf.d/[IP ADDRESS].conf

Code: Select all

server {
    listen       [IP ADDRESS]:80 default;
    server_name  _;
    access_log  /var/log/nginx/[IP ADDRESS].log main;
    location / {
         return 301 https://DOMAINNAME.com;
   }
}

Re: Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Thu Dec 06, 2018 2:54 pm
by thunder1
I know is way later,but I can confirm that is working on CentOS 7 too, same 1 IP, VPS.

Re: Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Tue Feb 26, 2019 4:11 pm
by mailarn
Please look: https://www.htaccessredirect.net/index.php

Everything must be written in the file .htaccess

Example:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^YOUR SITE[nc]
RewriteRule ^(.*)$ http://www.YOUR SITE/$1 [r=301,nc]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

YOUR SITE - change to your

good luck

Re: Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Sat Jun 01, 2019 10:04 pm
by adamjedgar
Of course remember htaccess doesn't work with standalone nginx

Re: Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Fri Jan 24, 2020 7:11 pm
by pawelcnet
create 2 files in /usr/local/vesta/data/templates/web/nginx/

redirect.tpl

Code: Select all

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    location / {
         return 301 https://%proxy_extentions%;
   }
   
   include %home%/%user%/conf/web/*nginx.%domain_idn%.conf_letsencrypt;
}
redirect.stpl

Code: Select all

server {
    listen      %ip%:%proxy_ssl_port%;
    server_name %domain_idn% %alias_idn%;
	ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
	
    location / {
         return 301 https://%proxy_extentions%;
   }
   
   include %home%/%user%/conf/web/*nginx.%domain_idn%.conf_letsencrypt;
}
How to use

In domain edit in Proxy Support -> Proxy Template select "redirect" and in Proxy Extensions type one domain without http or https just "somedomian.com" so your domain will redirect to "somedomian.com"

Re: Recommended way to redirect server IP to Domain?[Self Solve]

Posted: Tue Apr 28, 2020 8:45 pm
by delight
pawelcnet wrote:
Fri Jan 24, 2020 7:11 pm
create 2 files in /usr/local/vesta/data/templates/web/nginx/
...
Thank you for this suggestion!

Could you pls let me know how to redirect server ip to domain using nginx + php-fpm ?
There is no Proxy Support option in domain edit...