Virtual host on Apache 2 isn't working as excpected - apache

I'm trying to set a development server on my OSX 10.8.2. The deployed site name is mattat.org.il so I'd like to set it to mattat.dev.
These are the steps I followed:
Uncommented the include for virtual hosts, in httpd.conf:
Include /private/etc/apache2/extra/httpd-vhosts.conf
added a virtual host to httpd-hosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/matanya/Sites/matat"
ServerName mattat.dev
</VirtualHost>`
Added the server name to etc/hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost.
fe80::1%lo0 localhost
127.0.0.1 mattat.dev
Restarted Apache.
Now, when i go to localhost it takes me to the directory I've set for the virtual host, instead of taking me the the root directory (i.e Sites).
When I go to mattat.dev it is unidentified as a valid url, and simply interpreted as a Google search.
What am I missing?

.dev is not a valid TLD, your browser is not treating it as a URL. http://mattat.dev should work.
For not recognising localhost, check that you have a default directory in your httpd.conf for Apache to fall back on if it cannot find a virtual host, or alternatively add a second Virtual host for localhost.
<Directory "/Users/matanya/Sites/">
Options Indexes
Order allow,deny
Allow from all
</Directory>

Related

Virtual host will NOT work in MAMP but works on localhost:8888

Created a new Laravel project in htdocs in MAMP. Followed all the steps, added virtual hosts, changed conf file, etc/hosts, restarted mamp and my pc several times but I just can't get my virtual host to run.
however, when I am in the MAMP Dashboard I can navigate to my website -> website -> public and the default Laravel boilerplate page appears.
Has anyone had this issues with MAMP before? I gave up with XAMPP and Valet so it's my last chance here..
Specs
High Sierra 10.13.5 on 2015 MBP,
Composer version 1.6.5,
php 7.2.7
httpd.conf
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
httpd-vhosts
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "Applications/MAMP/htdocs/website/public"
ServerName website.dev
</VirtualHost>
etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
#255.255.255.255 broadcasthost
#::1 localhost
127.0.0.1 website.dev
website.dev is technically a public url, so the browser is looking for it on the internet I guess. I was trapped once in this dreadful situation. changing the name to something like website.local should solve your issue. It did for me.

Apache Server Unable to host multiple domain on single Public IP Error : "Not Found The requested URL / was not found on this server."

Apache Server Unable to host multiple domain on single Public IP running on Windows Server 2016
Error:"Not Found The requested URL / was not found on this server." 404 Not Found
Progress so far :
1)Edited Windows hosts file "C:\Windows\System32\drivers\etc\hosts": to below
127.0.0.1 localhost
::1 localhost
127.0.0.1 koffeeroasters.com
2)Changes made in the httpd.conf file of apache is below
changed
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf
also changed
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
and added to the end of the file the following
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wampstack/apache2/htdocs"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName koffeeroasters.com
ServerAlias www.koffeeroasters.com
# Folder where the files live
DocumentRoot "C:/wampstack/apache2/htdocs/koffeeroasters.com/"
# A few helpful settings...
<Directory "C:/wampstack/apache2/htdocs/koffeeroasters.com/">
Order Allow,Deny
Allow from all
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
Other details
I am using apache server on bitnami wampstack.
Site is available when typed the address "koffeeroasters.com" from the servers browser.
A reason for it which I know no solution of (refered from apache docs "https://httpd.apache.org/docs/2.4/vhosts/examples.html") :
Note :
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Thanks a bunch. All help appreciated.
Try changing this:
<VirtualHost 127.0.0.1>
to
<VirtualHost *:80>
This means allow any other IPs connect on port 80, which should get you going. Trying to match the localhost is doing more than you probably need, unless you are public facing server, in which case you will not want to do this.

Wamp 2.5 local host doesn't work after I have setup virtual hosts I get 403 forbidden error

I have setup virtual hosts now when I type localhost it does not work I figured that now I'll have to make a virtual host for local host it self and it worked but now when I type my external ip it does not work it says 403 forbidden so how do i fix this do I have to make a virtual host for my external ip and will it work for everyone or just my computer for example if I give to a friend and he typed my external ip will it work?
When you create Virtual Hosts, Apache ignored the host defined in httpd.conf i.e. localhost. So you have to create a vhost for localhost as well.
For security it should be the first vhost defined, as if someone just tries your ip address, Apache will default to the first vhost and that will be defined with only local access and they will get an error saying you are not allowed in.
As per your other question, you should only be allowing access to your .tk domains if the user actually enters a valid xxx.tk domain name and disallow access if they just use your wan ip address.
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.0 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>

wamp server: set up virtual host

I am setting a virtual host with wamp server following this tutorial
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
hosts file
127.0.0.1 localhost
127.0.0.1 dev.gamenomad.com
httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:\wamp\www\dev.gamenomad.com\public"
ServerName dev.gamenomad.com
ServerAlias dev.gamenomad.com
ErrorLog "logs/dev.gamenomad.com-error.log"
CustomLog "logs/dev.gamenomad.com-access.log" common
</VirtualHost>
<Directory C:\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I am unable to access dev.gamenomad.com . I got this error
i18n-values: Missing value for "primaryParagraph"
GET http://dev.gamenomad.com/ net::ERR_CONNECTION_REFUSED http://dev.gamenomad.com/:1
fyi, my apache server listen to port 8080 instead of the default 80. Does it affect my virtual host?
For wamp, you can set a virtual host using swamp UI as well. For that, you need to left-click on wamp icon -> Your Virtual hosts -> VirtualHost Management.
Then, just enter the server name, absolute path to the folder and then create the virtual host.
You can check it yourself here
Use gamenomad.git instead dev.gamenomad.com
And directory like Document root and goto c:\windows\system32\drivers\etc
Open the "hosts" file
And goto end line and type
127.0.0.1 gamenomad.git
Save change as administrator
End

Apache Virtual Host (Subdomain) access with different computer on LAN

I am currently trying to configure the Virtual Host (Subdomain) of my Apache HTTP Server so it can be accessed with another computer on my LAN. The current setup of Apache with PHP and MySQL works locally on the same physical machine.
So I have two Virtual Host setup (development and cms) running on a non-default port of 50080. The machine of the server have a IP of 10.0.0.10. From the same physical machine, I can access the two Virtual Host using:
development.localhost:50080
cms.localhost:50080
From a different physical machine, I can access the root of the server using:
10.0.0.10:50080
But I cannot or do not know how to access the Virtual Host from the different machine. I tried something like:
development.10.0.0.10:50080
cms.10.0.0.10:50080
But they do not seem to work.
Here's how my httpd-vhosts file looks like:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
I read some of the other post here and the Apache forum, but there's not exact case for this.
I was wondering how I can access the Virtual Host (Subdomain) from another machine and keep the same port if possible.
Thanks in advance
Ok, I figured it out, here are the configuration if anyone else is looking for this:
==================================================================================
Machine A (Apache HTTP Server):
httpd-vhost:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias alias <!-- Added -->
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.phoenix <!-- Added -->
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
hosts:
127.0.0.1 development.localhost
127.0.0.1 alias
127.0.0.1 development.alias
==================================================================================
Machine B (Guest Machine):
hosts:
10.0.0.10 alias
10.0.0.10 development.alias
From the second machine, you should be able to access with "alias" and "development.alias"
I suggest making the following change (add the ServerAlias lines):
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias cms.myserver.com
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.myserver.com
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
Restart Apache to ensure the changes take effect.
Then on your second computer you need to add a custom dns entry for these new domain names. If it is Windows, edit the file c:\windows\system32\drivers\etc\hosts. If it is Linux, edit /etc/hosts. Either way add:
10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com
Now on your second computer you should be able to access the following URLs:
http://development.myserver.com:50080
http://cms.myserver.com:50080
Unless I'm missing something, you'll need to either set up DNS entries, or add entries to the /etc/hosts file of each computer accessing the server.
localhost is an entry that exists in everyone's /etc/hosts file by default, always pointing to 127.0.0.1. Without adding a /etc/hosts entry, developer.localhost doesn't exist, and prefixing an ip address with a subdomain won't work at all.
Using a SSH + Putty tunnel, and thus having a 127.0.0.1 on my server, I managed to access my subdomains by doing the following on my server side:
# nano /etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com
I did not change the host file of the remote computer, and it works like a charm
For Named Virtual Hosts you need to use a hostname or domainname to connect to you apache server. It does not work with ips.
You could insert an entry in your /etc/hosts on your second system.