virtual hosts aren't resolving correctly - apache

I have the following vhosts config:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/mycheck.il"
ServerName mobile.mycheck
ErrorLog "logs/mobile.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/api.il"
ServerName api.mycheck
ErrorLog "logs/api.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/admin"
ServerName front.mycheck
ErrorLog "logs/front.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ErrorLog "logs/localhost.log"
</VirtualHost>
and using windows, I have the following hosts file
127.0.0.1 localhost
127.0.0.1 mobile.mycheck
127.0.0.1 api.mycheck
127.0.0.1 front.mycheck
However, no matter what vhost I try to put in my browser, I always resolve to the same directory (projects/mycheck.il), any idea how to fix this?

Try adding the following line before your VirtualHost declarations:
NameVirtualHost *:80

Related

Virtual Host With SSL Support on OS X Mavericks

I have a few virtual hosts setup on my local dev machine running Apache/2.2.24 on OS X 10.9 (Mavericks).
My http-vhosts.conf file (that is configured to load through httpd.conf looks like this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/me/Sites/testsite.com
ServerName testsite.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/me/Sites/testsite2.com
ServerName testsite2.dev
</VirtualHost>
I have also configured my /etc/vhosts file to contain this line:
127.0.0.1 testsite2.dev
I want to be able to use the testsite2.dev over SSL (https). I have tried multiple configurations of the vhosts config file with no luck.
With this current configuration, going to http://testsite2.dev pulls up the page I expect while https://testsite2.dev points to the apache home page at /Library/WebServer/Documents/index.html.en
I have tried the following configuration, and multiple others, that do not work:
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/me/Sites/testsite.com
ServerName testsite.dev
</VirtualHost>
<VirtualHost *:80 *:443>
DocumentRoot "/Users/me/Sites/testsite2.com
ServerName testsite2.dev
</VirtualHost>
Is it possible to have a virtual host listen on port 80 and port 443 on a local machine?
I figured out how to do this. I was simply missing a few directives to show where my certificate and key are located. Here's what I added:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /private/etc/apache2/ssl/server.crt
SSLCertificateKeyFile /private/etc/apache2/ssl/server.key
DocumentRoot "/Users/me/Sites/testsite2.com"
ServerName testsite2.dev
</VirtualHost>
Shown in context, my http-vhosts.conf file looked like this:
Listen *:443
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/me/Sites/testsite.com
ServerName testsite.dev
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /private/etc/apache2/ssl/server.crt
SSLCertificateKeyFile /private/etc/apache2/ssl/server.key
DocumentRoot "/Users/me/Sites/testsite2.com"
ServerName testsite2.dev
</VirtualHost>
If you don't have a certificate and key installed, you can create your own by following a tutorial like this one:
http://www.cfdad.com/2012/12/12/creating-a-self-signed-ssl-cert-for-mac-osx-mountain-lion-apache/
It should work on both Mountain Lion and Mavericks.

Fedora Apache: VirtualHost not picking up DirectoryIndex

I am having a problem with virtualhosting on my fedora 18 box.
http://127.0.0.1 works correctly and brings up index.html
http://127.0.0.1:9000 also works correctly.
http://localhost works
http://localhost:9000 does NOT work.
It just redirects to http://localhost
Why is not able to treat localhost and 127.0.0.1 the same way?
Here is the contents of my httpd-vhosts.conf:
Thanks in advance.
Listen 9000
DirectoryIndex index.html welcome.html
NameVirtualHost *:80
NameVirtualHost *:9000
<VirtualHost *:80>
ServerName saraslights
ServerAdmin ratteri#gmail.com
ServerAlias saraslights
DocumentRoot "/var/www/html/opencart"
ErrorLog "logs/saraslights-errors.log"
CustomLog "logs/saraslights-access.log" common
</VirtualHost>
<VirtualHost *:9000>
ServerName wordpress
ServerAdmin ratteri#gmail.com
ServerAlias wordpress
DocumentRoot /var/www/html/wordpress
ErrorLog "logs/wordpress-errors.log"
CustomLog "logs/wordpress-access.log" common
</VirtualHost>

How to enable multiple domains and or subdomains with apache httpd server

I'm trying to enable multiple domains in my environment Development, but am not succeeding the way I tried below, at which point I'm wrong?
I installed httpd and changed DocumentRoot in httpd.conf to:
C:/Webserver/www
*I changed the Windows hosts file to(in Italics would like to access):
If I switch to 127.0.0.1 api.rotadorock the address resolves to www/ but the right is www/rotadorock/api.
127.0.0.1 localhost
127.0.0.1 webserver
127.0.0.1/rotadorock/ecommerce rotadorock
127.0.0.1/rotadorock/api api.rotadorock
127.0.0.1/rotadorock/ecommerce ecommerce.rotadorock
127.0.0.1/rotadorock/mobile mobile.rotadorock
127.0.0.1/rotadorock/sistema sistema.rotadorock
127.0.0.1/rotadorock/social social.rotadorock
*Update(windows hosts file)
I removed the hosts file changes I mentioned above, because as #Volker Birk said are not necessary. But even so, still can not access as desire (api.rotadorock/ or localhost/api.rotadorock/ and should point to C:/Webserver/www/rotadorock/api). What could be wrong?
And finally changed httpd-vhost.conf for:
NameVirtualHost webserver:80
<Directory "C:/Webserver/www">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/Webserver/www"
ServerAlias localhost
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName webserver
DocumentRoot "c:/Webserver/www"
ServerAlias webserver
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost rotadorock:80>
ServerName rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost api.rotadorock:80>
ServerName api.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/api"
ServerAlias api.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost ecommerce.rotadorock:80>
ServerName ecommerce.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias ecommerce.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost mobile.rotadorock:80>
ServerName mobile.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/mobile"
ServerAlias mobile.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost sistema.rotadorock:80>
ServerName sistema.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/sistema"
ServerAlias sistema.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost social.rotadorock:80>
ServerName social.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/social"
ServerAlias social.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
You don't need the hosts file. Have a look into the documentation:
http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html
Finally solved the problem. And I could just using the Windows hosts file and httpd-vhosts.conf httpd together.
Let me give an example of what was done to enable multiple subdomains accessing locally.
On Windows hosts file to add, for each domain and subdomain you want something like this:
127.0.0.1 api.rotadorock #my subdomain
127.0.0.1 rotadorock #my domain
And then the httpd-vhosts apache httpd:
# Accessing the API
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/api"
ServerName api.rotadorock
ServerAlias ​​api.rotadorock
<Directory "C:/Webserver/www/rotadorock/api">
All Options Includes Indexes
</ Directory>
</VirtualHost>
# Accessing the domain
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/"
ServerName rotadorock
ServerAlias ​​*.rotadorock
<Directory "C:/Webserver/www/rotadorock/">
All Options Includes Indexes
</Directory>
</VirtualHost>
And then that way I could access api.rotadorock/ and rotadorock/ locally. I tried all ways without the hosts file. But just gotta use it. If someone can explain to me how it should have done so it would not need to use the hosts I would be grateful.

Multiple domains on one Apache server(WAMP)

I have got one IP address on my sv, and I want to set up two domains on one Apache Server with another DocumentRoot. Here is wat I got in httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\mail"
ServerName mail.A.pl
</VirtualHost>
<VirtualHost *:80>
ServerName B.eu
DocumentRoot "c:\wamp\www\B"
</VirtualHost>
<VirtualHost *:80>
ServerName A.pl
DocumentRoot "c:\wamp\www"
</VirtualHost>
Even when I try to load page: http://www.A.pl or www.B.eu or B.eu or A.pl it loads mail.A.pl.
What am I doing wrong?
EDITED
Here is new httpd-vhost, now it loads correct pages, but f.e. for A.pl doesn't show any images, and on mail.A.pl doesn't want to send POST data:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\mail"
ServerAlias mail.A.pl
ServerName mail.A.pl
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName B.eu
ServerAlias *.B.eu
DocumentRoot "c:\wamp\www\B"
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName A.pl
ServerAlias A.pl
DocumentRoot "c:\wamp\www"
</VirtualHost>
EDIT2
Thank you both for help.
I just switched first VirtualHost with last and it mistery started working :O
There are a few things that you need to have I think.
1) Uncomment the Virtual hosts line in Apache's config file so it includes httpd-vhosts.conf. On OSX that is:
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
2) Put the necessary lines in your hosts file ( http://en.wikipedia.org/wiki/Hosts_(file) ):
127.0.0.1 mail.A.pl
127.0.0.1 A.pl
127.0.0.1 B.pl
127.0.0.1 every.A.pl
127.0.0.1 subdomain.A.pl
127.0.0.1 needs-a-line.A.pl
The ServerAlias can go actually, you don't need that for subdomains, only for similar "main" domains.
Your httpd-vhosts.conf file is fine.
Why the images and POSTs are not working I don't know. That doesn't have anything to do with this host file. Perhaps with another .htaccess file.
You need to map NameVirtualHost to the IP address 127.0.0.1 for mapping multiple virtual host.
For example:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName myclient.local
DocumentRoot 'C:\wamp\www\ClientsMyClient'
</VirtualHost>
Have a look at this tutorial.

Different VirtualHosts with the same port

I need to have two VirtualHosts with the same listen port for different projects and with different logs. Here's what I've got:
<VirtualHost *:80>
DocumentRoot /home/projects/smk
ErrorLog /var/log/apache2/smk-error.log
RedirectMatch ^/$ /cms
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/projects/smk/cms
ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/projects/smk/deploy
ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>
Add different ServerName directive in all virtual hosts:
<VirtualHost *:80>
ServerName dev.localhost
DocumentRoot /home/projects/smk/cms
ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>
<VirtualHost *:80>
ServerName my-project.localhost
DocumentRoot /home/projects/smk/deploy
ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>
Don't forget to add host-entries for dev.localhost and my-project.localhost in /etc/hosts to 127.0.0.1 or whatever ip you want it to point to.
ServerName my-project.localhost
DocumentRoot /home/projects/smk/deploy
ErrorLog /var/log/apache2/smk-deploy-error.log
//Try adding Error document
ErrorDocument 404 404.html
There is a need to create a feedback in your application.