/etc/hosts configuration not being detected - linux

Am configuring a local linux development environment utilizing apache, i can access the url:
http://localhost:8080
but not the configured virtualhost entries which are also present in the /etc/hosts file e.g if i enter:
http://admin:8080
in my browser redirects me to www.admin.com, which is an external address.
/etc/hosts file has the following entries:
127.0.0.1 localhost admin jobboard
127.0.1.1 rob-VirtualBox
Apache config(virtual hosts reference the above entries admin and jobboard):
Listen 8080
Port 8080
ServerName 127.0.0.1:8080
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts"
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts">
NameVirtualHost *:8080
<VirtualHost 127.0.0.1:8080>
ServerName admin
# set the document root
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts/Client-asap.bigredsky.com"
# set the directory settings
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts/Client-asap.bigredsky.com">
Options All Includes Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1:8080>
ServerName jobboard
# set the document root
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts/JobBoard-asapdev.bigredsky.com"
# set the directory settings
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts/JobBoard-asapdev.bigredsky.com">
Options All Includes Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Apache and Computer was restarted after changes to config files were saved.
Is their some other hosts configuration file which needs to be modified? Running linux mint OS.
Thanks in advance.

in the virtual host config try this for admin
ServerAlias admin
that should resolve the admin website to local server
furthermore check whether you are under any proxy...you should turn it off...

create one more vhost entry for admin
<VirtualHost 127.0.0.1:8080>
ServerName admin

Related

Can linux host mutiple websites with one domain's different third domains?

I recently made some projects on raspberry pi with linux Debian Jessie, and I am interested in porting forward websites hosted on raspberry pi to a domain I owned.
From what I learned, it is possible to make each individual website on raspberry link with configured port according to apache , for example /home/pi/html/website01 -> port 11235 website02 -> 11236 so that I can browse the websites in private network. However, the domain I have is managed by godaddy, they provide the Chain without port, so that I can't redirect one of my third level domain(ex dashboard.domain.com to my dynamic dns hostname xx.dtdns.net with the port.
Is there any possible way or idea to get it work? I am lack of knowledge of nameserver, but I have an idea that using vpn or vps to map users to my private network instead of godaddy domain manager. I have alreay built the openvpn with cert and pptp vpn on my raspberrypi. Is it possible or what's next step?
Thanks, please give me some idea.
One solution would be to use Virtual Hosting in Apache on your Raspberry. Install Apache2 on PI with:
apt-get install apache2
Create a new conf file in /etc/apache2/sites-available or use an existing one. Add the ports for different site directories:
<VirtualHost *:11235>
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:11236>
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and then set Apache tolisten on the ports in the /etc/apache2/ports.conf file:
Listen 11235
Listen 11236
Restart the Apache service. You should now be able to browse both ports using the same ip address. If your ip was 111.111.111.111 then w1 directory on 111.111.111.111:11235 and 111.111.111.111:11236.
If your domain is pointing to a IP, you can use different hostnames without making change to DNS. If you domain was mydomain.com, you could instead add new virtual host names with:
<VirtualHost *:80>
ServerName w1.mydomain.com
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName w2.mydomain.com
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

How to configure linux/apache for multiple virtualhost in local machine

I have two local web site project, localgoogle.com and localapple.com.
localgoogle.com files are in /home/vahid/dev/localgoogle
localapple.com files are in /home/vahid/dev/localapple
My OS is debian 8.5, I have apache2 installed.
I made /etc/apache2/sites-available/localgoogle.com.conf
and /etc/apache2/sites-available/localapple.com.conf
both linked to /etc/apache2/sites-enabled and enabled by a2ensite command.
This is localgoole.com.conf:
<VirtualHost *:80>
ServerName localgoogle.com
ServerAdmin webmaster#localgoogle.com
DocumentRoot /home/vahid/dev/localgoogle
ServerAlias www.localgoogle.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
localapple conf file follow above configuration rule.
I restarted apache2 service, but I don't know why and how to access this virtualhosts from browser!
I tried localhost/localgoogle.com in browser but It's return Not Found
You access the site directly as localgoogle.com from your browser. Make sure that the name resolves to your local ip address using hosts file or dns.

Apache Multi-project configuration

I have a server with an ip: XXX.XXX.XXX.XXX
In my server, i have several projects in the folder /var/www:
/var/www/project1
/var/www/project2/trunk/webroot
...
My 000-default.conf is like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Currently I access into them through the following url:
XXX.XXX.XXX.XXX/project1
XXX.XXX.XXX.XXX/project2/trunk/webroot
...
I have a domain that targets to my server
domain.com -> XXX.XXX.XXX.XXX
My intention is to create a subdomain for each project, and each subdomain points to the target folder of the project:
project1.domain.com -> XXX.XXX.XXX.XXX/project1
project2.domain.com -> XXX.XXX.XXX.XXX/project2/trunk/webroot
(I think the best solution will be that XXX.XXX.XXX.XXX/project2 targets directly to XXX.XXX.XXX.XXX/proyect2/trunk/webroot)
I have read that it will be great that each project has its own .conf file in apache, and enabling each site separately.
But I think that if I create a VirtualHost *:80 for each project (project1.conf, project2.conf) they will be in conflict and I dont know how to do it.
Can anybody help me?
Regards.
Virtual Host is the way to go... create one virtual host for each domain pointing to a folder on your server where to webpage is sotored.
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
</VirtualHost>
Etc... One VirtualHost for each domain / DocumentRoot convination
Soruce: https://httpd.apache.org/docs/current/vhosts/examples.html
##################### EDIT
I have tested it on my own server
Whithout touching the default.conf file I have created two new config files
root#raspberrypi:/etc/apache2/sites-available# pwd
/etc/apache2/sites-available
root#raspberrypi:/etc/apache2/sites-available#
Please ignore the default files I have not touched them I have just created two new files named project1.... and project2....
root#raspberrypi:/etc/apache2/sites-available# ls
000-default.conf project1_domain_com.conf
default-ssl.conf project2_domain_com.conf
root#raspberrypi:/etc/apache2/sites-available#
root#raspberrypi:/etc/apache2/sites-available# cat project*
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project1/"
ServerName project1.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project2/"
ServerName project2.domain.com
</VirtualHost>
root#raspberrypi:/etc/apache2/sites-available#
ENABLING SITES
root#raspberrypi:/etc/apache2/sites-available# a2ensite project1_domain_com.conf
Enabling site project1_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available# a2ensite project2_domain_com.conf
Enabling site project2_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available#
RELOAD APACHE
root#raspberrypi:/etc/apache2/sites-available# /etc/init.d/apache2 reload
[ ok ] Reloading apache2 configuration (via systemctl): apache2.service.
root#raspberrypi:/etc/apache2/sites-available#
################# SUBDOMAIN EDIT
For example I have a single server with an IP XXX.XXX.XXX.XXX that have multiple domains registered (15 domains now).
I have one virtual host entry for each domain that works this way:
domain1.example.com -> Load the domain1 web index.html page (without /nothing/else )
domain2.example.com -> Load the domain2 web index.html page hosted on another folder expecified on the second virtual host.
And finally ussing a2ensite or a2dissite I enable or disable the website as a web hosting provider do...
If for any reason you need that accessing the host domain3.something.com it redirects to domain3.something.com/something/diferent ... it should be done on your server ussing .htaccess file and its a entirely diferent question :D

Subdomain not working on Apache/Linux

I'm trying to set up a subdomain for on a client's web server. It's a CentOS server running Apache. So say the website is "example.com". I'm trying to create "bugs.example.com".
So far, I've added to the vhost.conf file the subdomain info:
<VirtualHost *:80>
ServerName bugs.example.com
ServerAlias bugs.example.com
DocumentRoot /var/www/www.bugs.example.com
<Directory "/var/www/www.bugs.example.com">
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I've added the server's IP address and the subdomain to /etc/hosts:
111.222.333.444 bugs.example.com
I've created the directory for the website files, and an index page at:
/var/www/www.bugs.example.com/index.html
Sadly, I still get a "Server not found" error when I go to bug.example.com. What am I missing here? The example.com domain name is registered through GoDaddy.com. Is there something that needs to be done there?

How do I set up my hosts and httpd.conf files using a static IP address

I set Centos 6.3 up on a Rackspace box, using a static IP address (not a FQDN). I will be setting up virtual hosts on this box, and it seems to be working fine, but when I restart the HTTPD server, I get an error message "could not reliably determine the server's fully qualified domain name, using xx.xxx.xx.xx for ServerName" (xx.xxx.xx.xx is the static IP address for the server).
My /etc/hosts has the following in it:
27.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xxx.xx.xx name-used-for-rackspace
name-used-for-racspace is a name (not a FQDN) I used when I created the server (you have to enter a name).
I assume that I may not have to change anything in /etc/hosts, but what do I put in httpd.conf? right now, I have the following in that file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName localhost
<Directory /var/www/html>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
I also tried setting ServerName to xx.xxx.xx.xx, but I got the same error message.
This error is because you are not using a FQDN. It should not affect the operation of the webserver.
To get rid of the message on startup you'd need to configure your hosts file with the correct domain and IP address. Your httpd.conf should also use the same name (where you have localhost specified).
As long as your server is starting and you don't plan on assigning a domain to your webserver, this error can be ignored.
Example virtual host with FQDN:
<VirtualHost *:80>
ServerName www.domain.net
ServerAlias domain.net *.domain.net
ServerAdmin administrator#domain.net
DocumentRoot "/home/domain/htdocs"
<Directory "/home/domain/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
CustomLog "/home/domain/logs/access-www.log" common
ErrorLog "/home/domain/logs/error-www.log"
<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
</VirtualHost>
Example hosts file:
127.0.0.1 localhost localhost.localdomain gentoo1
x.x.x.x gentoo1.domain.net
You need to configure the network connection with your static IP, see reference below. Otherwise, your web server is working, but it's not accessible externally.
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_IPv4_Settings.html
Then put the static IP in the httpd.conf after server name.

Resources