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

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.

Related

Request to apache2 server always redirects to /var/www (Index of /) site

I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html. I have not registered an official domain but setup /etc/hosts/ to resolve example.com to the IP address of my server.
I created another conf file called example.conf under /etc/apache2/sites-available and enabled it with sudo a2ensite example.conf and disabled the 000-default.conf.
Now whenever I go to example.com in my browser I get served:
.
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html I get served the correct index.html.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/ as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.

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/

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

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

Redirecting an internal path to a virtual host

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