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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex