domain name converts to IP in browser bar, using apache webserver - apache

I'm trying to configure my new domain name to my home server running apache. I've set up httpd.conf in apache, so that I can access my website from the domain name on the web, the problem is that when I go to the domain name, the browser address changes to my server IP. The httpd.conf stuff I've set is:
#VIRTUAL DocumentRoot
#VIRTUAL ServerName
#VIRTUAL ServerAdmin
<VirtualHost *:80>
ServerAdmin ***
DocumentRoot "***"
ServerName ***
</VirtualHost>
On the domain side, I have an HTTP redirect to my server public IP. Can someone point me on the direction of what is supposed to be configured differently, thanks.

turns out I needed to find and edit the 'A Record' for my domain name provider, hidden away in advanced settings...changing from the domain provider IP to my server IP

Related

How to create own custom domain name for local-netwrok

I wanted to host one website in local Network.(it is not accessed by out side the network)
i install apache server.
how can i create own domain name for that(i don't want buy any domain name).
it is my virtual host file
ServerName testing.com
ServerAlias www.testing.com
DocumentRoot /var/www/testing.com/public_html
It works only when i put localhost as serverName
locahost file
127.0.0.1 somedomain.com

access to a server apache that has virtualhost

I have a cloud server with lampp installed on. I had configured a virtual host here like that:
<VirtualHost xx.xxx.xx.xxx:80>
DocumentRoot "/opt/lampp/htdocs/folder/"
ServerName www.xxx.com
</VirtualHost>
and everything work as i expect, if i go to www.xxx.com i see my 'folder' site.
Now i need to work to another site present on the same server, but it doesn't allready have a domain, so i had imagine (by reading the apache's configuration file explanation)that i have to do it in this way:
<VirtualHost xx.xxx.xx.xxx:80>
DocumentRoot "/opt/lampp/htdocs/folder/"
ServerName www.xxx.com
</VirtualHost>
<VirtualHost xx.xxx.xx.xxx:80/test>
DocumentRoot "/opt/lampp/htdocs/test/"
</VirtualHost>
But it doesn't work, if i do http://xx.xxx.xx.xxx:80 i reach the 'folder' site while if i do http://xx.xxx.xx.xxx:80/test rather the reach the 'test' site i still reach www.xxx.com, why? How could i reach this objective?
The virtual host defined first (top most) acts as default host. That one is used to respond to any incoming requests that are not matched by a specific host name in the request.
You want to try this setup:
# some fallback host for testing and development
<VirtualHost xx.xxx.xx.xxx:80>
DocumentRoot "/opt/lampp/htdocs/_default"
</VirtualHost>
# a virtual host with a specific host name
<VirtualHost xx.xxx.xx.xxx:80>
DocumentRoot "/opt/lampp/htdocs/example.com"
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
(here xx.xxx.xx.xxx stands for the systems public and routable IPV4 address)
In your file system you have this hierarchy:
/opt/lampp/htdocs/
_default/
test1/
test2/
example.com/
This way requests to http://example.com or http://www.example.com are mapped to the folder /opt/lampp/htdocs/example.com, requests to URLs with any other host name to the default folder /opt/lampp/htdocs/_default in which you now can create as many sub folders as you like for different applications.
Another approach would be to use other host names below your existing domain name for internal tests, so something like test1.example.com or similar. That way you do not have to use raw IP addresses with their routing risk.

Hosting multiple unnamed sites on same EC2 box

I know that I can have multiple websites hosted on the same EC2 box. The way I'm doing it is pointing Route 53 for the domain to the same box and in my httpd.conf file I'm adding something like this:
<VirtualHost *:80>
ServerName mywebsite.com
DocumentRoot "/var/www/html/website1"
</VirtualHost>
This works great for websites that have an assigned domain name.
What if I am still working on a site/application and don't have a domain name assigned to it?
<VirtualHost *:80>
ServerName <==what goes here if I don't have a domain name yet?
DocumentRoot "/var/www/html/website2"
</VirtualHost>
Is this even possible?
I tried just taking the IP of the box and going here: 54.32.XX.XX/website2/index.html
But this gives a 404.
How do I properly access this subdirectory?
Of note, the side in website1 is what I get when I just go directly to the IP (54.32.XX.XX) which I wouldn't expect since I have another site in the "main" directory /var/www/html/

IP of Web server stays in URL instead of showing Domain Name

So lets say I have the Domain Name "www.example.com" and have a "http-redirect" to server "1.1.1.1" where apache2 is running on Ubuntu 14.04 Server amd64.
I have all my web files on the server and they are working perfect.
What is not working right is the URL. Instead of "www.example.com/sites.php" if have "1.1.1.1/sites.php". How can I fix this?
What I did so far:
Disabled the default Virtual Host and created a new one:
<VirtualHost *:80>
ServerAdmin bla
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www
ErrorLog ...
CustomLog ...
</VirtualHost>
(It's typed, since I can't copy from my console..)
I tried to enter in the /etc/hosts
1.1.1.1 www.example.com
Thanks for any help
As discussed in comments, the reason that you see IP address in your browser is that http-redirect is pointing directly to to IP address, there's no domain name to display. Redirect just tells browser to go elsewhere and browser then fetches website from supplied URL, same as if you'd click on a link. If you redirect URL to 1.1.1.1/sites.php than that is what you will see in browser.

IP based VirtualHost and Apache

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.