I have this webserver that have an IP address xxx.xxx.xx.x, I also have a website I want to publish, but I do not have any domain for my website yet.
So in my httpd-vhosts.conf file I have this setting:
<VirtualHost xxx.xxx.xx.x>
ServerName xxx.xxx.xx.x
DocumentRoot "C:\Sites\mysite"
</VirtualHost>
And since I dont have a domain I really want to use the IP address to reach my site, but I have tried this and it does not work. I guess you HAVE to set a server name in ServerName as the title says.
Are there any ways for me to make my website public through my IP address, if yes how can I do this?
Try
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\Sites\mysite
ServerName xx.xx.xx.xx
</VirtualHost>
Remember to restart apache,
You may also need to add,
Listen xx.xx.xx.xx:80
If you only have the one website on this server, you don't need a virtual host. Just set the DocumentRoot correctly and away you go. Also make sure Apache is listening on all IP addresses (Listen 0.0.0.0:80.)
If that doesn't work for you, from your command prompt do:
telnet xx.xx.xx.xx 80
GET /
and see what you get back - you should get your website's default page.
This is not a programming question.
But anyway,
Set the VirtualHost to * rather than a specific IP address. I don't think you need the servername either then.
Related
I've been trying to create 3 different domains linking to 3 different sites on the same machine, 2 which works but the third on the different port links to the first page.
My apache config looks like this:
Listen 81
NameVirtualHost *:81
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /var/www/www2
</VirtualHost>
<VirtualHost *:81>
ServerName controlpanel.example.com
DocumentRoot /var/www/controlpanel
</VirtualHost>
I've used Bind9 to set up the domains.
www IN A 123.123.123.123
www2 IN A 123.123.123.123
controlpanel IN A 123.123.123.123
www and www2 works fine and shows the correct site, however controlpanel.example.com also links to the first www site. When I enter the port manualy on the ip, xxx.xxx.xxx.xxx:81, i get linked correctly. The thing is that I don't really know where I'm doing it wrong, this is the first time I'm trying anything like this. You got any ideas?
Im also running this on an old ubuntu 12.04 server.
Regarding where you're going in the comments for the previous answer:
You could add a port 80 virtualhost for controlpanel.example.com and put a single statement inside,
Redirect / http://controlpanel.example.com:81
The purpose of the ServerName is not to inform the browser what port your webserver is using. It's used for name-based virtualhosts and as a last resort for self-referential links (out of the box, self-referential links are generated with whatever the client already thought it was accessing via the Host: header)
But there is definitely something quite bizarre about your requirement. Usually the motivation is to not use custom ports, and if they are, to address the server with a low port and have the por remapped by some intermediary (load balancer, proxy).
If you want your third virtualhost to be simulataneously the defautl on port 81 and a name-based option on port 80:
Change
<VirtualHost *:81>
to
<VirtualHost *:80 *:81>
Apache finds the set of virtual hosts with the best IP:PORT based match first, then if NameVirtualHost also matches, starts looking at the ServerNames from that set.
I have installed CentOS 6.5 on my VPS (IP 149.210.167.9). Eventually I want to serve multiple domains, but for now I only want to handle 1 domain in particular: aforismo.eu. When you surf to the IP directly it shows me an Apache test page, so that works. When I ping aforismo.eu it shows me the correct IP, so I think the DNS is setup correctly. If I'm missing something trivial, please teach me :)
What I did so far to handle this domain:
I) I've created /etc/httpd/conf.d/site-aforismo.conf
<VirtualHost *:80>
ServerAdmin webmaster#aforismo.eu
DocumentRoot /var/www/aforismo.eu/public/
ServerName aforismo.eu
ServerAlias *.aforismo.eu
ErrorLog logs/aforismo.error_log
CustomLog logs/aforismo.access_log common
</VirtualHost>
II) Modified a few bits in /etc/http/conf/httpd.conf:
Include conf.d/*.conf
NameVirtualHost *:80
III) Afterwards I've restarted apache
service httpd restart
IV) Checking httpd -S results in:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 vps.vanoosten.me (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server aforismo.eu (/etc/httpd/conf.d/site-aforismo.conf:1)
port 80 namevhost aforismo.eu (/etc/httpd/conf.d/site-aforismo.conf:1)
wild alias *.aforismo.eu Syntax OK
But ... surfing to http://www.aforismo.eu (or http://aforismo.eu) does not work. Since it's not my everyday business, I'd sure miss something quite trivial, but I can't find out what it is. Can you help me a bit further? Much appreciated.
You may need to add Listen *:80.
You may also need to add UseCanonicalName off under <VirtualHost *:80>.
Edit:
Unless it's meant to be internal only, there is something wrong with your DNS. I can hit the IP but aforismo.eu doesn't resolve to anything.
Update: As you guys suggested, it turns out to be a DNS issue. I thought I had created an A record to the given IP. But ... in the interface of my DNS provider I had to use the #-character for the domain itself instead of to really write it down. So what I really created was an A-record for aforismo.eu.aforismo.eu. Fixed (and next time I promise to read the manual :P)
I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *
It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?
Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
<VirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
<VirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...
I managed to set up virtual hots on my local machine, but I kinda run into a wall now.
Normally, when you type localhost/ into browser you will see what you are supposed to see. But after I have set my virtual hosts, anything I type goes to the vhost. I cant figure a way to have a virtual host AND the old functionality together.
Here is my vhost file (btw, I am using xampplite)
<VirtualHost domain.eu>
ServerName domain.eu
DocumentRoot /www/domain
ServerAlias *.domain.eu
</VirtualHost>
<VirtualHost domain.sk>
ServerName domain.sk
DocumentRoot /www/domain
</VirtualHost>
The second one gets redirected to sk.domain.eu via htaccess. When I add these 3 lines to vhosts, localhost starts working, but even the other vhosts go to /www/
<VirtualHost localhost>
DocumentRoot /www
</VirtualHost>
But to comment/uncomment these 3 lines everytime I need to localhost is stupid. Any advice how can I keep both of them working together?
Thanks for your time
You really shouldn't be using domain names in the VirtualHost declarations.
If these three virtual hosts have different IP address, you should be putting their respective IP addresses into the VirtualHost blocks, and never mention NameVirtualHost.
If they use the same IP address, you must be using NameVirtualHost, and then you must, in each virtual host, repeat the name in the very same spelling that you did in the NameVirtualHost declaration.
Try adding this before the VirtualHost containers:
NameVirtualHost localhost
NameVirtualHost domain.sk
NameVirtualHost domain.eu
I have been working on a drupal test site for a while, which has a bunch of virtual hosts set up like this:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
</VirtualHost>
I have been using a modified host file to view each of these test sites, along the lines of:
12.0.0.1 localhost
20.02.2.22 testsite1.example.com
20.02.2.22 testsite2.example.com
20.02.2.22 testsite3.example.com
This has worked fine, however now I need to send the sites over to some people remotely who are not technical enough to modify their own host files and see it the way I do.
Is there a way I could set up Apache so that the url "http://20.02.2.22/testsite1" would forward to testsite1.example.com internally? I am using Drupal, and the site setup needs to see the "testsite1.example.com" so that it can correctly choose the instance to select. I have been looking through apache rewrite, but I am a bit of a newb at this so any help is much appreciated.
testsite1.example.com will only be resolved on your machine, so you cannot redirect. You can set up proxy with mod_proxy. Hope this works for you:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
ServerAlias 20.02.2.22
<Location /testsite1/>
ProxyPass http://testsite1.example.com/
</Location>
</VirtualHost>
The way I show my local test sites is a combination of Dynamic DNS and port-forwarding.
Internally, my Drupal site is at [my machine ip] or localhost.
I setup a free dynamic dns name to my IP and then on my router, accept incoming requests on port to route to [my machine ip]
That way, they can see yoursite.dyndns.com, but its looking at your local copy.
Why you just don't buy a new domain name and point it to your server IP address...
Or there are free domain solutions like:
http://www.dot.tk/en/index.html?lang=en
or
http://dyn.com/dns/
If you wanna buy new domain, i recommending you this one, cheap and quality service: http://server2.elite7hackers.us/recommend.php?site=godaddy