3

here is my /etc/httpd/conf.d/test.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName test.dev
    ServerAlias test.dev.*.xip.io
    DocumentRoot /var/www/html/user/test/web
    ErrorLog "/var/www/html/user/test/app/logs/httpd_error.log"
    CustomLog "/var/www/html/user/test/app/logs/httpd_access.log" combined
    <Directory "/var/www/html/user/test/web">
        # AllowOverride All      # Deprecated
        # Order Allow,Deny       # Deprecated
        # Options All
        # Allow from all         # Deprecated
        # Require all granted    # << New way of doing it
        Options +FollowSymlinks +Indexes
        AllowOverride all
    </Directory>
</VirtualHost>

Accessing http://test.dev.192.168.1.4.xip.io/ successfully redirects me to the proper website. Accessing http://192.168.1.4/ also redirects me to the same website instead of the index that I was expecting to see. Also, accessing http://test.dev-some-random-string.192.168.1.4.xip.io/ will also redirect me to the same website.

How do I configure this so when I try to access test.dev.192.168.1.4.xip.io, I will end up in page I am coding while accessing 192.168.1.4.xip.io will show me the home page.

I am currently using a centos 6 running in a virtual box with a bridged adapter for the network. Here is my /etc/httpd/conf/httpd.conf.

http://pastebin.com/iFBin5Lu

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
kapitanluffy
  • 139
  • 1
  • 1
  • 8

2 Answers2

0

If you define only one virtual host, then all requests to httpd will be served by that virtual host, whether or not they match the ServerName or ServerAlias, because the first virtual host is also the default virtual host. Search for "default virtual host" in the Apache "Name-based Virtual Host Support" documentation.

Note also that once you define any virtual hosts, the default ServerName goes away, and you have to define a new vhost to recreate it if you still want to use it. See the inset "Main host goes away" at the above link.

So, try defining a default virtual host, which can be as simple as

<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

and make sure it comes before all of your other virtual hosts in the configuration. Then any requests that don't match the other virtual hosts will be served by that one.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
-1

You need to define a VirtualHost for every website that you want to show; even if 192.168.1.4 is the main one, you also need to define a VirtualHost where define "ServerAlias 192.168.1.4". If there's only one VirtualHost, you will be redirected always to the site defined in ServerAlias.

consuela
  • 115
  • 8
  • 1
    A virtual host for every web page? – Andrew Schulman Jun 07 '15 at 08:32
  • If you want to set only a URL, you don't need to configure VirtualHosts. As soon you as you want to host two web sites on the same IP/host, if you only configure only one VirtualHost, Apache will redirect you to that site. So, for the first site, you need to configure also a VirtualHost with the ServerAlias as the URL of the first site. – Paco Bernabé Pellicer Jun 07 '15 at 10:31