Skip to main content

How to put different host entries on same linux server, for different virtual hosts? [closed]



The setup is : Two applications are hosted on same linux server using vhost entries in apache configuration. say :





http://greatapp.example.com





and





http://superapp.example.com





Both of them have a functionality where they do server side http request to a third url (using php cURL / file_get_contents) :





http://apis.example.com





Now there is a host entry of an in the hosts file '/etc/hosts'







xx.xx.xx.xx apis.example.com







This is only intended for greatapp.example.com code, and not for superapp.example.com.





How to configure the server such that greatapps.example.com uses the host entry, but superapp.example.com uses the public ip of apis.example.com


Comments

  1. Launch Notepad and open the hosts file located at C:\windows\system32\drivers\etc\hosts (You may not be able to see the windows folder–some files are hidden by default under Windows.)
    On Vista, you’ll also need to have access to change the hosts file. To do that, launch Notepad by right clicking on Notepad from the Start menu and choosing "Run As Administrator." This will give you permission to edit and save the file.
    At the end of that file type: 127.0.0.1 clientA.local
    Save and close the hosts file.
    In Notepad open the Apache configuration file located at C:\xampp\apache\conf\extra\httpd-vhosts.conf
    At the bottom of that file add.

    NameVirtualHost *
    <VirtualHost *>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
    </VirtualHost>
    <VirtualHost *>
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
    ServerName clientA.local
    <Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>



    The first five lines of code turn on the Virtual Host feature on Apache, and set up the C:\xampp\htdocs folder as the default location for http://localhost. That’s important since you need to be able to access the XAMPP web pages at http://localhost/ so that you can use PHPMyAdmin.


    Save and close the Apache configuration file, and restart Apache from the XAMPP control panel.
    Start a Web browser and type a URL for the virtual host. For example: http://clientA.local/


    You should now see the home page for your site.

    If you want to add additional Virtual hosts add the proper entry to the hosts file and add another block of text like that in yellow above to the Apache configuration file. For example, say you had another Web site for ClientB. You’d add 127.0.0.1 clientB.local in the hosts file and the C:\xampp\apache\conf\extra\httpd-vhosts.conf would look like this:

    NameVirtualHost *
    <VirtualHost *>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
    </VirtualHost>
    <VirtualHost *>
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
    ServerName clientA.local
    <Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    <VirtualHost *>
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website"
    ServerName clientB.local
    <Directory "C:\Documents and Settings\Me\My Documents\clientB\website">
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    ReplyDelete
  2. It cannot be done directly: host name space is global per host.

    You could run one of the apaches in a virtual machine with a different /etc/hosts file.

    ReplyDelete
  3. Here's how I would do it:


    Each of my apps will have a config file that will be read. That config file can specify what url to use. You can use existing libraries to read config files. In this example I will use Zend_Config_Ini. Here's what your config file can look like for great app:



    [settings]

    urls.third_party = 'xxx.xxx.xxx.xxx'


    This is one is for superapp


    [settings]

    urls.third_party = 'http://apis.example.com'


    2.Read the url from a config file using Zend_Config_Ini for example:

    require_once 'Zend/Config/Ini.php';
    $config = new Zend_Config_Ini('application.ini', 'settings');
    $app_config = $config->toArray();

    $third_party_url = $app_config['urls']['third_party'];


    I think you're more flexible this way as you can easily change the url in the config file of the app concerned easily.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.