AWS 53号路线 - 路由通往数字海洋托管项目的路线

发布于 2025-02-01 19:17:06 字数 1612 浏览 4 评论 0 原文

我创建了两个新项目,并用同一滴在数字海洋中部署了它。一个是django,第二个是节点JS项目。

该域实际上是在AWS中托管的,因此第一个已经有效的是,

    sample.maindomain.com (django)
    maindomain.com (nodejs) //currently trying to figure out how route this domain toi nodejs project

可以说数字海洋的IP地址为167.162.169.224,

因此路由53是像这样配置的,

     Recordname             Type     Routing         Value/Route traffic to
     sample.maindomain.com  A        Simple          167.162.169.224
     maindomain.com         A        Simple          what should be the value ?

我在nginx中创建了两个单独的文件,因为反向曲线看起来像这样

// sample.maindomain.com(django)

    server {

           Server_name sample.maindomain.com www.sample.maindomain.com

           location /
             ................


    

// maindomain.com(nodejs)

    server {
           server_name maindomain.com www.maindomain.com
           
           root /home/projectdir/nodejsproject;
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
}

}}

           ....................
           .......................

,所以问题是,我如何路由 maindomain.com ,因此它将指向nodejs project nginx nginx nginx配置海洋?

实际上,如果该项目部署在EC2实例中,则将域或子域指向cname的添加子域更容易,例如 EC2-19-19-192-192-107-202.EU-CENTRAL-12.EU-CENTRAL-1.COM

I created two new projects and deployed it in Digital ocean in same droplet. One is a django and second is a node js project.

The domain is hosted in aws actually, so the first one already works

    sample.maindomain.com (django)
    maindomain.com (nodejs) //currently trying to figure out how route this domain toi nodejs project

Lets say the Digital oceans' IP address is 167.162.169.224

So the Route 53 is configured like this

     Recordname             Type     Routing         Value/Route traffic to
     sample.maindomain.com  A        Simple          167.162.169.224
     maindomain.com         A        Simple          what should be the value ?

I created two separate files in nginx as reverse-proxy looks like this

//sample.maindomain.com(django)

    server {

           Server_name sample.maindomain.com www.sample.maindomain.com

           location /
             ................


    

// maindomain.com(nodejs)

    server {
           server_name maindomain.com www.maindomain.com
           
           root /home/projectdir/nodejsproject;
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
}

}

           ....................
           .......................

So the question is, how can I route the maindomain.com so it will point to the nodejs project nginx configuration hosted in Digital Ocean?

Actually if the project is deployed in Ec2 instance, its more easier to add subdomains by pointing the domain or subdomain to CNAME like ec2-19-192-107-202.eu-central-1.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜未央樱花落 2025-02-08 19:17:06

您必须将同一个公共IP用于两个主机名,并根据Web请求的主机字段向右后端发送液滴发送请求。

所谓的虚拟托管

有很多示例如何使用nginx进行操作,这只是一个随机的示例:https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks- Virtual-Hosts-on-ubuntu-16-04

You have to use the same public IP for both hostnames and make your droplet send requests to the right backend based on the Host field of the web requests.

What is called Virtual Hosting.

There are a lot of examples how to do that with nginx, this is just a random one: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

樱花落人离去 2025-02-08 19:17:06

我试图删除和重新创建虚拟设施并重新启动服务器几次,但它不起作用。Nginx配置是正确的,指向精确的项目位置,但仍然指向其他工作项目。

经过大量谷歌搜索后,我意识到我需要在项目中添加SSL证书并使用Certbot https://www.nginx.com/blog/ususe-free-ssltls-certificates-from-lem-lets-cerrypt-encrypt-with-nginx/

我是不知道为什么添加SSL证书为我解决了问题

I tried to delete and recreate the virtualhosts and restarting the server few times but it did not working.The nginx config is correct and pointing to exact project location but still its pointing to other working project.

After many googling, I realised that I need to add ssl certificate to the project and install it using certbot https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/

I am not sure why after adding ssl certificate solves the problem for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文