如何使 ip 指向 AWS 上的其他 IP 和端口(来自两个 apache 虚拟主机)



我需要在 EC2 实例上具有指向特定 IP 地址和端口的不同 IP 地址,其中我在 Apache 虚拟主机上运行了多个站点 例如: xx.xx.xx.xx -> 107.22.56.213:8080 yy.yy.yy.yy -> 107.22.56.213:8081

这在 AWS 上可行吗?

编辑 1:

好的,我已经将两个不同的 IP 地址附加到一个实例。但是我在配置反向代理时遇到问题,我的 000-default.conf 是这样的:

<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>

但它仍然显示默认的 000 默认站点,并且我已经重新启动了 apache2 服务

您可以在 ec2 服务器上连接多个弹性网络接口,并使用弹性 IP 连接每个弹性网卡,您可以将 aoache 虚拟配置为侦听特定 IP 和特定端口:

这是一个非常有用的博客

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

对于代理,下面的 URL 与您有类似的情况:

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/ 

我知道这不是你要求的100%,但是将NGINX服务器放在Apache服务器前面很容易,而且大多数时候它的性能更好。 Nginx配置(带缓存(就像...

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;
} 
} 
}

我对我的许多服务器都这样做了,它工作得很好,在您的源服务器上,您可以指定缓存标头,以便上层 NGINX 服务器将缓存它们,只要您指定:

<?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); 
?>

使用类似的配置,我的统计数据显示页面加载时间为 0.250 秒,从 0.800 秒开始。

最新更新