0

I have a server. I installed and configured Virtualmin/Webmin on it. Also I added three domains and configured almost 100% correct all DNS records.

My big question is how I restrict accessing website through server IP. Or how to redirect the IP to a specific location from my server to load specific files?

2
  • can you provide an example ?
    – nux
    Jan 30, 2014 at 13:53
  • I have three domains. I've added them to the server ( create virtual hosts, dns records, etc) They work fine. Lets say my domains are a.com b.com and c.com and my server ip is 1.1.1.1 , first time when I added a.com I was also able to access a.com using 1.1.1.1, then after I added b.com, when I was typing 1.1.1.1 into my browser it shows me b.com website, then after I added c.com , when I type 1.1.1.1 I see c.com website. I don't want this to happen. I want 1.1.1.1 to show something else like /var/www/somefolder . Does it makes sense? Jan 30, 2014 at 14:11

2 Answers 2

2

You should use virtualhosts for that. Something along lines

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/ip_address_root
ServerName 123.123.123.123

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

(Example copied from here)

Alternatively, mod_rewrite helps with this. Something like

RewriteCond %{REMOTE_HOST}  ^123\.123\.123\.123$
RewriteRule .* http://www.example.org/you_are_using_ip_address [R=301]
0

Try to map the ip to localhost in /etc/hosts

1
  • That's not going to help at all, unless you do it on all client computers, which might be difficult.
    – Olli
    Jan 31, 2014 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .