How to create multiple website using one IP adress (apache2) - apache

I installed ubuntu server 16.10 on VirtualBox recently in order to host a website on it thanks to apache2.
I followed some tutorials to do it, but here's the issue : it doesn't work :/
I mean, when I use ifconfig, I get the following IP : 10.41.175.36
If I type this IP in the URL, I get the default html page for apache. So this is good, I guess, I'm able to access this webpage from any devices if they're connected to the same wifi.
Now I want to create 2 websites on my ubuntu server, I created one index.html in /var/www/site1 and one in /var/www/site2, I configured the .conf in /etc/apache2/sites-available for the 2 websites, I restard the apache2 and enabled the websites.
Now, I tried to enter the domain name I gave them but It tells me that the URL isn't known.
I edited the /etc/hosts to change domain name and it doesn't work.
So do you have a tip or a tutorial in order to create the websites ?
I hope I was clear, thank you.

You should check out VirtualHosts on Apache2. https://httpd.apache.org/docs/2.4/vhosts/examples.html

Related

Apache in Ubuntu: How Access by IP to multipe sites in the same webserver?

I have a Webserver with Ubuntu 16.04 and Apache 2.4. In that, I have in /var/inetpub/ some sites' files. Example:
/var/inetpub/site1.com/...
/var/inetpub/site2.com/...
/var/inetpub/site3.com/...
/var/inetpub/site4.com/...
I can access this sites when I am in my LAN, editng my computer's hosts file, adding the server IP, like:
192.168.1.10 site1.com
192.168.1.10 site2.com
192.168.1.10 site3.com
192.168.1.10 site4.com
With this, I can open my browser and paste the site1.com or site2.com and the web is displayed. But, now I need this sames sites to be visible in my mobile. So, before getting into something like trying to modify the equivalent in the mobile phone to the hosts file (which worth mentioning that I tried a long time ago, I lost a whole day and it did not work), I wonder if there was a simpler alternative, such as being able to access the sites through IP.
Right now, if the type the ip (192.168.1.10) in my mobile phone browser, obviously connected in my LAN, it shows me the first site (site1.com). So,
Is there any configuration that allow me to do the same with the other site? I don´t know, something like:
http://192.168.1.10/site1.com
http://192.168.1.10/site2.com
http://192.168.1.10/site3.com
http://192.168.1.10/site4.com
Maybe?
Someone could tell me that it would be easier add the urls to the local DNS of my network, but at the moment it is not an option, since I do not have access to such configuration, and getting it or having someone with such access to help me, is something... Complicated and slow.
Thanks for your help.
I thank it’s more easy if you can edit your mobile's hosts.But it not easy,you need got the root access of your android mobile.And i don't know how to do this on ios.
Optionally,edit the router's dns is work too,but it not easy too...
There is a option,you are build a DNS server on your ubuntu,then change you mobile's DNS. But it's difficult.

How to change apache2 127.0.0.1 name from localhost to another domain?

Sorry if this question is stupid, but I am a newbie when it comes to apache and servers in general and I have been trying but I can only find windows only answers. I'm running an apache server on a mint vm. When I type localhost, it redirects to the page automatically, same as doing 127.0.0.1 or 127.0.1.1. Now, I want to change this to another domain name, but not a website one. Like, I want to change from the word localhost to another word, like 'local'. I have been unable to find answers, I have read about virtual hosts but I don't think that is it because I'm only running one website instance. This is just an example website btw, it's just a index.html file for me to learn how to configure things. I have changed my 000-default.conf to say ServerName thenameIwant but it doesn't work. I noticed it says that this is the last resort host what is the first one?
To be able to use local to connect to your server, you would use local as a domainname which resolves to localhost or 127.0.0.1. You could do this by editing your hosts file. Depending on your os this file is stored in different places. Just google 'Change hosts file [your os]'. And add the following line: local 127.0.0.1.
The default apache server is set to listen for any domain, also local.

Changing the URL of an HTTPS server

Hello Stack Overflowers,
I am a newbie to servers (and Linux in general). I have recently made an HTTP server on Kali Linux (formerly BACKTRACK). When I type in http://localhost/ it works and my HTML page shows up. BUT I want to change the URL to be https://localhost/ The server software that I am using is Apache.
Thank you for your help in advance.
Thomas
https://localhost means, that your Computer does not fetch the site from the internet. You can test this by trying to view your site while offline - this will work.
If you want another domain name, you have to put your site on the internet.
Find a hosting provider, make a contract, choose a name for your site that's not already taken, load up your page.
Be aware that this might cost something.
If you want to change the name only locally, open the file /etc/hosts
as superuser.
It should look like
# Comments Here
127.0.0.1 localhost
# End of /etc/hosts
Add
# Comments Here
127.0.0.1 localhost yourdomain.name
# End of /etc/hosts
Note that your site then can only be viewed on your computer.

Multiple Virtual Hosts Subdomain 404s?

I have an Apache Server running on a CentOS box running 3 websites using VirtualHosts.
The problem is, is when I go to a non-existent subdomain on the websites it always shows the files from Website #1. How do I fix this?
Thanks!
Here's my httpd.conf: http://pastebin.com/5bDgrR2W (I've replaced my email and domain names)
You have a default host configured, so whenever an unknown domain is called, the default config will be used.

IP address is shown in address bar instead of domain

I have a WAMP home web server up and running on a static IP and registered a domain with Namecheap, but I'm a bit shaky with DNS. At first I used URL Redirect and pointed it to my IP. This meant that when you typed in the domain (like example.com) it just redirected you right to my IP, replacing the domain name with it in the address bar. Now I'm trying to get the domain to show instead of the IP in the address bar, which I'm struggling to understand exactly how to do.
The latest thing I've tried which many people say to do is instead of using URL Redirect to use the A (Address) record type and point it to my IP, which I thought would finally fix my problems. Of course after 15 min or so when it all got updated I'm getting a 400 Bad Request with nginx under it in Firefox, and a blank page in Chrome. Now I'm getting blank pages in both. Did I do something wrong here? Do I need to edit something on the web server such as httpd.conf? Am I going at this completely wrong?
Yes you should do away with the redirect and instead create an "A record". The sub-domain entry would typically be, but is not restricted to "www". The record type "A" and destination/target would be your external IP address. Once you update this record it may take several hours before you notice it taking effecting, upon where on people typing your URL would be directed to your web server.
You will need to forward port 80 on your router to the server hosting WAMP.
Finally the WAMP server should be provided with your domain name so it knows which site to load. If use the VirtualHost file this will allow you to host multiple domains on your web server. To do this...
Uncomment the following line so it appears like below in your Apache httpd.conf, to allow Apache to use virutal hosts
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then locate the httpd-vhosts.conf file, should be found in your WAMP installation location, such as C:\wamp\bin\apache\apache*version_number*\conf\extra\
Add an entry for your site, altering the details to your own domain name and website location.
<VirtualHost *:80>
ServerName www.stackoverflow.com
ServerAlias stackoverflow.com
DocumentRoot "C:/websites/stackoverflow/"
ErrorLog "C:/websites/stackoverflow/logs/error.log"
CustomLog "C:/websites/stackoverflow/logs/access.log" common
</VirtualHost>
Now restart your WAMP server and give it a whirl.
Tip: If your server won't start after these changes, check that you have created the folder structure for the log files!
Solution described here could resolve this issue.
Most of the free dynamic dns providers, allow acquiring more than one free host name. If allowed you can solve the problem by getting a second name, e.g., mysite2.somefree.org.
Now, go and configure your free domain names in the dashboard of free provider in the following way (assume your IP is 188.165.15.29 and your server's listening to port 8085).
redirect mysite1.somefree.org to mysite2.somefree.org:8085
redirect mysite2.somefree.org to your dynamic IP, say, to 188.165.15.29
This also works when you are using Apache httpd server alone, not being part of WAMP. You do not need to tweak virtual host or any part of your server. You only configure inbound direction.
Use Forward with masking where you registered your domain. mine is GoDaddy.
in the forward settings, you will see this at bottom of the page. click Forward with masking and add the title you want them to see in the address bar of the browser when they go to your site. instead of showing your IP address