在亚马逊S3水桶托管多个网站亚马逊、多个、水桶、网站

2023-09-11 09:40:48 作者:扶着往事走

     我工作的一个应用程序,用户可以创建自己的HTML模板,并将它们发布到当用户点击发布我要与他选择的名称的子域创建主机他的网站web.Now(EX:他名字的网站苹果,我创建了一个子域apple.ABC.com)。      在应用程序中的单个用户可以创建多个网站/ templates.Now,我想存储单个用户的网站在一个bucket.If用户有两个模板的例如:apple.com和berry.com 我有两个文件夹中的桶,每一个网站。但是我通过S3斗去了,我发现我可以设置主机​​上的水桶和网站的规则。 我想知道,如果我想做是可能的,如果不是我如何管理它,就好像我创建一个桶一个模板,这将是困难的,我跟踪哪些用户有多少模板,在数据库中,我将有有多个条目。我知道我将不得不使用AWS服务和API的存储模板S3,我很感兴趣,如果我能有多个网站水桶。

I am working on an application where user can create his own html templates and publish them to the web.Now when the user clicks publish I want to create host his website on a subdomain with a name he selects.(EX: he names the site apple,I create a subdomain apple.ABC.com). In the application a single user can create multiple websites/templates.Now,I want to store a single users websites in a single bucket.If a user has two templates Ex: apple.com and berry.com ,I have two folders in the bucket,one for each website.But I went through the S3 bucket,and I found I can set hosting rules on the bucket and the website. I wanted to understand if what I am trying is possible and if not how can I manage it as if I create one bucket for one template,it will be difficult for me to track which user has how many templates as in the DB I will have to have multiple entries.I am aware I will have to use AWS services and API's to store the templates to S3,I am interested if I can have multiple websites in a BUCKET.

编辑:想出一个解决方案,使用代理服务器nginx的和更新的答案

推荐答案

这是一个有点棘手,但doable.After一些研究,我发现了一个解决方案,可以work.Steps如下: 1)我们需要以执行操作的代理服务器(如:Nginx的) 2)我们需要的配置更改default.conf文件的代理请求你有你的网站的水桶。 3)这是conf文件:

This is a bit tricky but doable.After some research I found a solution that can work.Steps are as follows: 1) We need a proxy server in order to perform the operations.(eg:Nginx) 2) We need to make config changes to the default.conf file to proxy requests to the bucket you have your website. 3) This is the conf file:

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

4)现在,在您的DNS设置中更改您的CNAME到你的代理服务器的地址(类似于 router.abcd.com ),代理服务器将你的请求,并转发它的S3存储在您的网站托管。 5)此外,还可以使用 wwwizer.com 的IP地址 @ record.This将您的请求发送到正确的目标而不管 WWW 在你的URL。

4) Now in your DNS settings change your CNAME to your proxy server address(Something like router.abcd.com).The proxy server will take your request and forward it to the S3 bucket where your site is hosted. 5) Also,you can use wwwizer.com ip address for @ record.This will send your request to correct destination irrespective of the www in your URL.