问题描述
限时送ChatGPT账号..我正在尝试为我的 EC2 实例配置一个虚拟主机.我在我的 EC2 实例和 apache2 上使用 ubuntu 作为网络服务器.
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
我希望人们只能使用 IP 地址访问 app_A 和 app_B(我已将弹性 IP 附加到我的 EC2 实例),如 http://my.ip.address/app_A 和 http://my.ip.address/app_B.至于/var/ww/mywebsite 中的应用程序,我希望人们能够通过我的域mywebsite 访问它.我已将该域指向我的 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. 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
指向 var
中的 www
文件夹.这个想法是 apache 把它作为主要的配置文件,因此你可以根据需要定义任意数量的 .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.
现在,那些必须有什么?这取决于您需要什么,但这几乎是您需要的:
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/">
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
ServerAdmin youremail@provider
SetEnv VAR_IF_YOU_NEED_ONE VALUE
RewriteEngine on
DocumentRoot "/var/www/mywebsite/"
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屋!
更多推荐
[db:关键词]
发布评论