如何在运行Ubuntu的AWS EC2上配置多个虚拟主机? [英] How to configure multiple Virtual Hosts on AWS EC2 Running Ubuntu?

查看:132
本文介绍了如何在运行Ubuntu的AWS EC2上配置多个虚拟主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的EC2实例配置虚拟主机。我在EC2实例和apache2上将ubuntu用作Web服务器。

I'm trying to configure a virtual host to my EC2 instance. I'm using ubuntu on my EC2 instance and apache2 as web server.

我在/ var / www的3个不同文件夹中有3个应用程序(基于Web):
-/ var / www / app_A
-/ var / www / app_B
-/ var / www / mywebsite

I have 3 applications (web-based) in 3 different folders in /var/www: - /var/www/app_A - /var/www/app_B - /var/www/mywebsite

我想要别人只能使用 http中的IP地址(我已将弹性IP附加到我的EC2实例)访问app_A和app_B ://my.ip.address/app_A http://my.ip.address/app_B 。至于/ var / ww / mywebsite中的应用程序,我希望人们能够通过我的域mywebsite.com进行访问。我已将域指向我的EC2 IP地址(my.ip.address)。

I want people to only be able to access app_A and app_B using IP address (I've attached elastic IP to my EC2 instance) as in http://my.ip.address/app_A and http://my.ip.address/app_B. As for the application in /var/ww/mywebsite, I want people to be able to access that through my domain mywebsite.com. I've point the domain to my EC2 IP address (my.ip.address).

我知道我必须创建虚拟主机才能实现此目的,但是我真的很新。我一直在尝试使用Google解决方案,并尝试了几种解决方案,但一直失败。

I know I have to create virtual hosts to be able to achieve this, but I'm really new at this. I've been trying to google the solution, and tried several solutions but keep failing.

请告诉我如何正确设置虚拟主机,以便达到编写的目的

Please tell me how to setup a virtual host correctly so I can achieve my purpose written above.

推荐答案

这很简单,因为已经安装了apache,您将能够看到一个名为: / etc / apache2 / sites-enabled / 000-default ,它指向中的 www 文件夹var 。这个想法是apache将其作为主要配置文件,因此您可以根据需要定义尽可能多的 .conf 文件,因此,您可能希望具有以下内容: / p>

It's pretty simple, as you have the apache already installed you'll be able to see a file called: /etc/apache2/sites-enabled/000-default which point to your www folder within var. The idea is that apache takes it as the main config file, hence you can define as many .conf files as you need so, you might want to have something like this:

/etc/apache2/sites-enabled/
├── 000-default -> ../sites-available/default
└── subsystems
    └── appA.conf
    └── appB.conf
    └── appMyWebSite.conf

因此,它更容易处理,因为您可以将所有内容分割成多个conf文件,并且可以根据需要进行配置。

So it's easier to handle because you have everything segmented into several conf files, as many as you need.

现在,那些必须具备什么?这取决于您的需求,但这几乎就是您所需要的:

Now, what those must have? It depends on what you need but this is pretty much what you need to have:

<Directory "/var/www/mywebsite.com/">
    Options Indexes Includes FollowSymLinks MultiViews +ExecCGI
    AddHandler cgi-script cgi pl
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.cgi index.html
</Directory>

<VirtualHost *:80>
    ServerName mywebsite.com
    ServerAdmin youremail@provider.com
    SetEnv VAR_IF_YOU_NEED_ONE VALUE
    RewriteEngine on

    DocumentRoot "/var/www/mywebsite.com/"

    LogLevel warn
    ServerSignature Off

    #And whatever you need take a look to apache documentation
</VirtualHost>

因此,您可以将域名指向相同的服务器IP地址,而apache将根据这些域的名称(即,所有域都使用相同的IP)

So you can point your domain names to the same server ip address, and apache will handle that depending on the name of those domains (i.e. same ip for all your domains)

希望这会有所帮助。

这篇关于如何在运行Ubuntu的AWS EC2上配置多个虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆