Announcement

Collapse
No announcement yet.

Apache - different sites on ip address and server name

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Apache - different sites on ip address and server name

    Hi
    I have been looking how to set Apache up so if somebody browse to it via ip address he gets one site, but if using dns name - go to a different site (so sites are on the same box but different folders).
    Thanks

  • #2
    Re: Apache - different sites on ip address and server name

    I've never used Apache but what you're looking for is to set the host header value for the site with the DNS name.

    Check out this link: http://httpd.apache.org/docs/2.2/vhosts/name-based.html

    If that doesn't work then look through this search: http://www.google.com/search?q=Apatc...w=1920&bih=930

    I should note that you can only split up HTTP traffic this way. If both sites need HTTPS you'll need to use an additional IP address and bind one to each site.
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Apache - different sites on ip address and server name

      Thanks for your reply Jeremy,
      What I am actualy looking for is to set it up so if, lets say, I have a website www.mysite.com on ip 12.23.34.45, if anybody enters www.mysite.com in address bar - he gets to one site (from folder C:/WWW/htdocs/mysite), but if he enter ip address 12.23.34.45 in the browser address bar - he gets to another site on my server (from folder C:/WWW/htdocs/mysite).
      Hope this is more clear.
      Thanks again
      Roman

      Comment


      • #4
        Re: Apache - different sites on ip address and server name

        yes, you can do this.
        Apache call them VirtualHosts

        dependent on your config files, you may have /etc/apache2/sites-enabled
        there will be a config file for each vhost
        for instance:
        Originally posted by /etc/apache2/sites-enabled/default
        DocumentRoot /var/www
        <Directory />
        Options FollowSymLinks
        AllowOverride All
        </Directory>
        <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        </Directory>
        Originally posted by /etc/apache2/sites-enabled/wp
        Servername svr-001
        <VirtualHost dev.domain.com.au:80>
        DocumentRoot /var/www/wordpress
        ErrorLog /var/log/apache2/wordpress.error.log
        </VirtualHost>
        Obviously there's quite a bit more too it, and it would neccesitate the reading of some documentation to figureo ut how to make it work for your situation.

        I wouldn't recommend having all the data under /var/www though - at least use subdirectories, else you'll find anyone who knows the path might be able to access content for separate sites.
        Please do show your appreciation to those who assist you by leaving Rep Point https://www.petri.com/forums/core/im.../icon_beer.gif

        Comment


        • #5
          Re: Apache - different sites on ip address and server name

          Originally posted by Roman_k View Post
          Thanks for your reply Jeremy,
          What I am actualy looking for is to set it up so if, lets say, I have a website www.mysite.com on ip 12.23.34.45, if anybody enters www.mysite.com in address bar - he gets to one site (from folder C:/WWW/htdocs/mysite), but if he enter ip address 12.23.34.45 in the browser address bar - he gets to another site on my server (from folder C:/WWW/htdocs/mysite).
          Hope this is more clear.
          Thanks again
          Roman
          Hi Roman,

          Yes, I understood what you're asking. The link I provided is what you're looking for. Tehcamel has provided some of the same information. Let us know if you have any follow up questions on the implementation.
          Regards,
          Jeremy

          Network Consultant/Engineer
          Baltimore - Washington area and beyond
          www.gma-cpa.com

          Comment


          • #6
            Re: Apache - different sites on ip address and server name

            Ok,
            I have one IP address and want to run 2 sites.
            This is how its set up at moment (real names changed):
            ------------ part of httpd.conf --------------
            ################# Site1 ############################
            <VirtualHost *:80>

            DocumentRoot "C:/WWW/htdocs/public/site1/"
            ServerName site1.co.uk
            ServerAlias www.site1.co.uk
            <Directory "C:/WWW/htdocs/site1/">
            Options Indexes FollowSymLinks
            DirectoryIndex index.php index.html
            AllowOverride all
            Order allow,deny
            Allow from all
            </Directory>
            </VirtualHost>
            ####### site2 ############################
            <VirtualHost *:80>
            DocumentRoot "C:/WWW/htdocs/public/site2/"
            ServerName site2.net
            ServerAlias www.site2.net
            <Directory "C:/WWW/htdocs/public/site2/">
            Options Indexes FollowSymLinks
            DirectoryIndex index.php index.html
            AllowOverride all
            Order allow,deny
            Allow from all
            </Directory>
            </VirtualHost>
            ------------------------------------------------
            Whatever name I use to go to website I get the site which virtual host is first in httpd.conf. So if I put virtual host for site2 first in httpd.conf I will get site2 in browser if use site1 or site2 url or ip address.
            Thanks ideas?
            Thanks

            Comment


            • #7
              Re: Apache - different sites on ip address and server name

              From what I can tell it looks like the VirtualHost directives are configured properly.
              Did you include the "NameVirtualHost" directive in the config?

              e.g.

              Code:
              NameVirtualHost *:80
              
              <VirtualHost *:80>
                DocumentRoot "C:/WWW/htdocs/public/site1/"
                ServerName site1.co.uk
                ServerAlias www.site1.co.uk 
                <Directory "C:/WWW/htdocs/site1/">
                      Options Indexes FollowSymLinks
                      DirectoryIndex index.php index.html
                      AllowOverride all
                      Order allow,deny
                      Allow from all
                </Directory>
              </VirtualHost>
              
              <VirtualHost *:80>
                  DocumentRoot "C:/WWW/htdocs/public/site2/"
                  ServerName site2.net
                  ServerAlias www.site2.net
                  <Directory "C:/WWW/htdocs/public/site2/">
                      Options Indexes FollowSymLinks
                      DirectoryIndex index.php index.html
                      AllowOverride all
                      Order allow,deny
                      Allow from all
                  </Directory>
              </VirtualHost>
              Regards,
              Jeremy

              Network Consultant/Engineer
              Baltimore - Washington area and beyond
              www.gma-cpa.com

              Comment

              Working...
              X