I have 3 IPs in my server, I want use them to increase twitter API limits.

How to set a different ip for a directory in centos 6.1 httpd.conf (Apache 2.3.1)

I added these line in the bottom of httpd.conf

<VirtualHost NEW IP:80>
    ServerName mydomain.com/subdir
    ServerAlias www.mydomain.com/subdir
    DocumentRoot /var/www/html/subdir
    <directory "/var/www/html/subdir">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from all

But when I test /var/www/html/subdir/index.php with code

function get_server_ip() {
    if (isset($_SERVER)) {
        if($_SERVER['SERVER_ADDR']) {
            $server_ip = $_SERVER['SERVER_ADDR'];
            $server_ip = $_SERVER['LOCAL_ADDR'];
    }else {
        $server_ip = getenv('SERVER_ADDR');
    return $server_ip;
echo get_server_ip();

it still return OLD IP (default ip for my server). So is it possible and how? If it couldn't, how to use 3 IPs to increase twitter API limits.


Doing an apache configurations is not enough. To make it work you have to configure multiple IP Address into your Centos (RedHat) box.

Assuming that you have only one phisical network interface eth0, then you have this file that contain all the relevant parameters :

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0

(This is a sample statical ip configuration for IP=, yours may and will vary)

All this is explained here: CENTOS-Network Configuration Files and CENTOS-Interface Configuration Files

To assign another IP to the same phisical network interface eth0 do this (as root) :

$ cd /etc/sysconfig/network-scripts/
$ cp ifcfg-eth0 ifcfg-eth0:1
$ vi ifcfg-eth0:1

and then change IPADDR to the new file (and check/change all the other parameters)

You can do the same for third new IP doing cp ifcfg-eth0 ifcfg-eth0:2 and edit the file.

Then you have to restar network to apply changes (stop apache before):

$ service network restart

Check the new config :

$ ifconfig 

You will see listed the interface configuration for eth1 , eth1:1 , eth1:2 (and probabily more iterfaces like lo -> loopback )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.