skip to Main Content

I need to have different IP addresses pointing to an specific ip address and port on a EC2 instance, where i have running multiple sites on Apache virtual hosts
For example:
xx.xx.xx.xx -> 107.22.56.213:8080
yy.yy.yy.yy -> 107.22.56.213:8081

Is this posible on AWS?

EDIT 1:

Ok I have attached two different IP addresses to a single instance. But I am having problems configuring the reverse proxy, my 000-default.conf it is like this:

<VirtualHost 54.158.187.139:80>
  ProxyPass / 127.0.0.1:8080
  ProxyPassReverse / 127.0.0.1:8080
</VirtualHost>
<VirtualHost 35.153.37.243:80>
  ProxyPass / 127.0.0.1:8081
  ProxyPassReverse / 127.0.0.1:8081
</VirtualHost>

But it is still showing the default 000-default site, and I have already restarted the apache2 service

2

Answers


  1. You can attach multiple elastic network interfaces on your ec2 server and attach each ENI with elastic IP, you can configure your aoache virtual to listen to specific IP and specific port:

    This is a very useful blog

    https://aws.amazon.com/blogs/aws/multiple-ip-addresses-for-ec2-instances-in-a-virtual-private-cloud/
    https://vannstudios.com/how-to-set-up-multiple-elastic-ip-for-amazon-ec2-instance

    for Proxy the URL below has a similar case to you:

    https://serverfault.com/questions/557478/apache-reverse-proxy-forwarding-different-source-ip-ranges-to-different-destinat

    RewriteCond %{REMOTE_ADDR} 54.158.187.139
    RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [P]
    ProxyPassReverse / http://127.0.0.1:8080 
    
    RewriteCond %{REMOTE_ADDR} 35.153.37.243
    RewriteRule ^/(.*) http://127.0.0.1:8081/$1 [P]
    ProxyPassReverse / http://127.0.0.1:8081/ 
    
    Login or Signup to reply.
  2. I know it is not 100% what you asked, but it’s easy to put a NGINX server in front of Apache one, and it performs better most of the time.
    Nginx config (with caching) is as simple as …

    http{
    
        proxy_cache_path /my_nginx_cache_folder levels=1:2 keys_zone=my_nginx_cache:2g max_size=2g
                         inactive=30d use_temp_path=off;
    
    
        server {
    
            listen       443 ssl;
            server_name  www.mydomain.com;
    
            ssl_certificate         /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;
            ssl_certificate_key     /etc/letsencrypt/live/www.mydomain.com/privkey.pem; 
    
            location / {
    
                    proxy_pass  http://mydomain-on-anotherip.com:8081;
    
                    # the domain to request at the above IP
                    proxy_set_header Host      mydomain.com;
    
                    proxy_set_header X-Real-IP $remote_addr;
    
                    # for this path, tell it to use the cache defined above
                    proxy_cache             my_nginx_cache;
    
            } 
        } 
    }
    

    I did this with many of my servers and it works nicely, and at your source server, you can specify cache headers, so that the upper NGINX server will cache them for as long as you specify:

    <?php 
        $cache_seconds = 60*60*24;
        header("Expires: ".gmdate('D, d M Y H:i:s GMT', time()+$cache_seconds));
        header("Cache-Control:public, max-age=".$cache_seconds); 
    ?>
    

    With a similar config, my stats show pages load in 0.250 seconds, from 0.800 seconds.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search