我正在开发一个应用程序,用户可以在其中创建自己的html模板并将其发布到web.Now当用户点击发布时,我想在他选择的名称的子域上创建主机他的网站。(EX:他命名网站苹果,我创建了一个子域apple.ABC.com)
在应用程序中,单个用户可以创建多个网站/模板。现在,我想将单个用户网站存储在一个存储桶中。如果用户有两个模板 Ex:apple.com和berry.com 我在存储桶中有两个文件夹,每个网站一个。但我通过S3存储桶,我发现我可以在存储桶和网站上设置托管规则。
我想了解我正在尝试的是否可能,如果不能如何管理,就像我为一个模板创建一个存储桶一样,我很难跟踪哪个用户有多少模板,就像我将拥有的数据库一样有多个条目。
我知道我将不得不使用AWS服务和API将模板存储到S3,如果我可以在BUCKET中拥有多个网站,我感兴趣。
编辑:使用代理服务器nginx找出解决方案并更新答案
答案 0 :(得分:4)
要使用s3的静态网站功能,每个存储桶只能映射一个域。没有办法告诉域使用存储桶的文件夹而不是存储桶本身。
答案 1 :(得分:2)
这有点棘手,但可行。经过一些研究,我找到了一个可行的解决方案。步骤如下:
这是conf文件:
server {
# Listen on port 80 for all IPs associated with your machine
listen 80;
# Catch all other server names
server_name _;
# This code gets the host without www. in front and places it inside
# the $host_without_www variable
# If someone requests www.coolsite.com, then $host_without_www will have the value coolsite.com
set $host_without_www $host;
if ($host ~* www\.(.*)) {
set $host_without_www $1;
}
location / {
# This code rewrites the original request, and adds the host without www in front
# E.g. if someone requests
# /directory/file.ext?param=value
# from the coolsite.com site the request is rewritten to
# /coolsite.com/directory/file.ext?param=value
set $foo 'http://sites.abcd.com';
# echo "$foo";
rewrite ^(.*)$ $foo/$host_without_www$1 break;
# The rewritten request is passed to S3
proxy_pass http://sites.abcd.com;
include /etc/nginx/proxy_params;
}
}
现在,在您的DNS设置中,将您的CNAME更改为您的代理服务器地址(类似router.abcd.com
)。代理服务器将接收您的请求并将其转发到托管您网站的S3存储桶。< / p>
@
记录。这会将您的请求发送到正确的目的地,而不管您网址中的www
。