在AWS EC2上运行Ubuntu的虚拟主机 [英] Virtual Host on AWS EC2 Running Ubuntu

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

问题描述

我想配置虚拟主机,以我的EC2实例。我使用的是Ubuntu的在我的EC2实例的Apache2作为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.

我有3个应用程序(基于网络)的在/ var / WWW 3种不同的文件夹: - 在/ 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

我希望人们只能够访问app_A和app_B使用的IP地址(我已附加弹性IP到我的EC2实例),如的 HTTP://my.ip.address/app_A 的http://我的。 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).

我知道我要创建虚拟主机要能做到这一点,但我真的在这个新的。我一直在试图给谷歌的解决方案,并尝试了几种解决方案,但要失败。

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.

推荐答案

这是pretty的简单,因为你已经在Apache已经安装,你就可以看到一个名为: /等/启用站点的Apache2 / / 000默认这点你的 WWW 文件夹中的 VAR 。这个想法是,阿帕奇将其作为主要的配置文件,因此,你需要那么你可以定义为许多 .conf文件文件,你可能希望有这样的事情:

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.

现在,这些东西必须有?这取决于你所需要的,但是这是pretty的很多东西你需要有:

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)

希望这有助于。

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

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