托管服务器ip绑定域名

by BinHong Lee

李彬宏

如何在一台服务器上托管多个域名和项目 (How to host multiple domain names and projects on one server)

NGINX是一种神奇的工具 (NGINX is one magical tool)

I own multiple domain names, and each one hosts a different side project. For the longest time, everything that required ‘hosting’ was hosted on Heroku. But their free tier can be quite limited, it can also get costly quickly if you are paying for each separate project. So instead, I decided to explore putting all of them together using NGINX (recommended to me by Jane Manchun Wong).

我拥有多个域名,每个域名托管一个不同的副项目。 在最长的时间内,所有需要“托管”的内容都托管在Heroku上。 但是他们的免费套餐可能非常有限,如果您为每个单独的项目付费,它的价格也会很快上涨。 因此,我决定使用NGINX(由Jane Manchun Wong推荐给我)探索将它们全部组合在一起。

所需资源 (Required Resources)

虚拟专用服务器(VPS) (Virtual Private Server (VPS))

You’ll need a virtual server such as DigitalOcean or EC2 by AWS. Personally I uses Vultr (here’s the non-referral link) which costs me about $2.50 / month.

您将需要一个虚拟服务器,例如AWS的 DigitalOcean或EC2。 我个人使用Vultr (这是非推荐链接 ),每月费用约为2.50美元。

网站域名 (Domain Names)

You will need to register a few domain names. Assuming that you probably already have them, make sure your domain names are pointing at the name servers of your VPS. There should be a DNS section in your domain name service dashboard where you can select “custom DNS” or something similar. If you are not sure what the nameservers of your VPS are, you should be able to find that info easily through a simple search of “nameserver” + VPS service name.

您将需要注册一些域名。 假设您可能已经拥有它们,请确保您的域名指向VPS的名称服务器。 域名服务仪表板中应有一个DNS部分,您可以在其中选择“自定义DNS”或类似名称。 如果不确定VPS的名称服务器是什么,则应该可以通过简单地搜索“名称服务器” + VPS服务名称来轻松找到该信息。

设置NGINX (Setting up NGINX)

安装和基本设置 (Installation and basic setup)

Reference from How To Install Nginx on Ubuntu 16.04

如何在Ubuntu 16.04上安装Nginx的参考

Run the following commands through SSH-ing into the VPS. It will install NGINX, set firewall rules allowing it, and set NGINX to autostart on boot.

通过SSH运行到VPS中运行以下命令。 它将安装NGINX,设置允许它的防火墙规则,并将NGINX设置为在启动时自动启动。

配置设置 (Configuration setup)

Reference from Host Multiple Domains on One Server/IP with Apache or nginx

使用Apache或nginx从一台服务器/ IP上的主机多个域进行引用

The default virtual.conf location should be at /etc/nginx/conf.d/virtual.conf. I recommend backing up the default file before making any changes. (If it doesn’t exist, you can just create it.) Edit the file to look something like the following:

默认的virtual.conf位置应位于/etc/nginx/conf.d/virtual.conf。 我建议在进行任何更改之前备份默认文件。 (如果不存在,则可以创建它。)编辑文件,使其类似于以下内容:

Here are a few things to look at:

这里有几件事情要看:

  • server block — Each of these should represent each different domain or subdomain in use.

    服务器块-每个服务器块都应代表正在使用的每个不同域或子域。

  • root — This is the location where the (HTML) files are loaded from.

    根目录 -这是(HTML)文件的加载位置。

  • server_name — (sub)domain name(s) that should load these specific files.

    server_name-应该加载这些特定文件的(子)域名。

  • proxy_redirect — in cases where you are redirecting a specific subdomain to an active server, you will want to add this and put the IP location after it. (For local servers, either http://127.0.0.1:port or http://localhost:port should work as intended.)

    proxy_redirect-在将特定子域重定向到活动服务器的情况下,您将要添加该地址并将IP位置放在其后。 (对于本地服务器, http: //127.0.0.1 :porthttp:// localhost:port应该可以正常工作。)

sudo systemctl restart nginx

After you are done, restart the server so the new configurations will be loaded and applied.

完成后,重新启动服务器,以便新的配置将被加载和应用。

克隆和链接 (Cloning and linking)

Now remember, since you have your directory pointing at /opt/htdocs/websiteName, your initial thought might be to clone your projects into these folders. This can work, but it’s not ideal since many operations in these folders require root access to really do anything.

现在请记住,由于您的目录指向/ opt / htdocs / websiteName ,因此您最初的想法可能是将项目克隆到这些文件夹中。 这可以工作,但是不是理想的,因为这些文件夹中的许多操作都需要root访问权限才能真正执行任何操作。

Instead, you can clone them into your user folder or anywhere else like you normally would, and then create a soft link to connect the path to your repository folder. Something like this:

相反,您可以将它们克隆到您的用户文件夹中或像往常一样复制到其他任何位置,然后创建一个软链接以将路径连接到存储库文件夹。 像这样:

git clone git@github.com:binhonglee/binhonglee.github.io ~/websitesudo ln -s ~/website /opt/htdocs/binhong

Of course, when you are cloning a Node.js static site folder (ReactJS, Angular or Vue.js), you will want to install (npm install) and build (npm run-script build) them. Then link the ./build folder instead of the base level of the cloned repository. (Similarly for Jekyll sites, but use the ./_output folder instead.) As for active servers, just make sure your server is running on the same port as it is listed in the configuration file.

当然,当您克隆Node.js静态站点文件夹(ReactJS,Angular或Vue.js)时,您将需要安装( npm install )并构建( npm run-script build )。 然后,链接./build文件夹而不是克隆存储库的基本级别。 (与Jekyll站点类似,但是使用./_output文件夹。)对于活动服务器,只需确保服务器在配置文件中列出的端口上运行即可。

使用certbot设置HTTPS (Set up HTTPS with certbot)

Thanks to Let’s Encrypt, you can now get free and easy HTTPS certificates. With the introduction of certbot, everything just got even easier!

多亏了“让我们加密”,您现在可以获得免费和便捷的HTTPS证书。 随着certbot的推出,一切都变得更加轻松!

Reference from How To Secure Nginx with Let’s Encrypt on Ubuntu 16.04

在Ubuntu 16.04上如何通过Let's Encrypt保护Nginx的参考

Just run the above for all your domain and subdomain names and certbot will take care of everything. If you were to renew the certs, you can run the following so the certbot will help you renew your SSL certificate.

只需为您的所有域名和子域名运行以上内容,certbot就会处理所有事情。 如果要续订证书,则可以运行以下命令,以便certbot可以帮助您续订SSL证书。

sudo certbot renew --dry-run

更新一切 (Updating everything)

Now that you have everything up and running, you might be thinking, well there seems to be an awful lot to remember if/when I need to update something. Unfortunately, that’s kinda true, but we can always make it easier by adding a script that does it for us.

现在您已启动并运行了所有内容,您可能会在想,好在我需要更新某些东西时似乎要记住很多事情。 不幸的是,这确实是正确的,但是我们总是可以通过添加可以为我们完成任务的脚本来使其变得更容易。

Here is how one would look:

这是一个什么样子:

Thanks for reading! Let me know if you have any questions in the comments below.

谢谢阅读! 如果您在下面的评论中有任何疑问,请告诉我。

关于我 (About me)

At the time of writing, I work at Apple Inc. in the role of Siri Language Engineer as an Independent Contractor through AdvantisGlobal. I spend a lot of my free time experimenting and building new things with technologies I find fun and interesting. Follow my exploration journey here or on GitHub.

在撰写本文时,我在Apple Inc.工作,是通过AdvantisGlobal作为Siri语言工程师的独立承包商。 我将大量的业余时间花在使用有趣且有趣的技术进行实验和构建新事物上。 在这里或在GitHub上跟随我的探索之旅。

其他参考 (Other References)

  • nginx proxy pass redirects ignore port on serverfault

    Nginx代理传递重定向忽略 serverfault上的 端口

  • Continue SSH background task/jobs when closing SSH on superuser

    在超级用户上关闭SSH时继续SSH后台任务/作业

翻译自: https://www.freecodecamp.org/news/how-you-can-host-multiple-domain-names-and-projects-in-one-vps-7aed4f56e7a1/

托管服务器ip绑定域名

托管服务器ip绑定域名_如何在一台服务器上托管多个域名和项目相关推荐

  1. 我的世界在线服务器地址,私の世界_我的世界1.7.10服务器地址大全 我的世界1.7.10服务器ip大全_游戏堡...

    第3页:私の世界 基本信息 服务器名称:私の世界 有效状态:长期开放 支持版本:1.7.10/1.7.9/1.7.8/1.7.7/1.7.6 营利模式:基础免费+多种内容收费 游戏模式:生存 网络类型 ...

  2. dell服务器管理口ip地址_批量自动化配置Dell服务器idrac管理口IP

    背景说明 工作中经常会遇到一次上几十台.几百台服务器的情况 每当到这个时候小伙伴们拿台笔记本和一根网线,一台服务器.一台服务器的去修改idrac IP 为了节约这个工作量,利用dell的racadm工 ...

  3. 北京dns服务器ip地址_什么是DNS? 域名系统,DNS服务器和IP地址概念介绍

    北京dns服务器ip地址 介绍 (Introduction) By the end of this article, you should have a better understanding of ...

  4. 上传图片在浏览器可以正常查看 在手机不显示_自己拥有一台服务器可以做哪些很酷的事情...

    买了云服务器后,打算来折腾一下服务器.服务器都有哪些用途? 建网站.博客.图床内网穿透.反向代理私人网盘 下面是具体流程: 购买云服务器ECS 点击[阿里云服务器ECS] (https://www.a ...

  5. 自己建服务器 语音盒子_如何自己搭建一个服务器?

    以前不懂服务器是什么,就知道可以搭建网站.后来去阿里云注册了账号,看见学生活动才114一年就买了,配置很垃圾,是对于初学者来说还不错. 想着当时也够傻,没有一点基础,还作死地装了一个linux系统.完 ...

  6. 单台mysql增加节点_如何在一台服务器上安装两个PXC集群节点

    我认为在单个物理服务器上运行2个或多个Percona XtraDB Cluster(PXC)节点这样没有什么意义,除了教育和测试目的,但在这种情况下这样做仍然是有用的.最受欢迎的实现方式似乎是服务器的 ...

  7. web服务器虚拟目录_调整专用虚拟Web服务器

    web服务器虚拟目录 When you get a dedicated virtual server to run your website, chances are good that it's c ...

  8. 服务器ip显示cdn,怎么查看cdn原服务器ip

    怎么查看cdn原服务器ip 内容精选 换一换 网站的访问与云服务器的网络配置.端口通信.防火墙配置.安全组配置等多个环节相关联.任意一个环节出现问题,都会导致网站无法访问.本节操作介绍网站无法访问时的 ...

  9. 我的世界优化服务器ip,我的世界1.9.4服务器ip

    我的世界1.9.4服务器地址是小编从网上共享所得,主要为我的世界1.9.4版本的游戏玩家提供方便,服务器不多,需要的朋友可以到本站查看,然后进入对于服务器和其他游戏玩家畅玩我的世界. 我的世界1.9. ...

  10. minecraft服务器搭建教程_我的世界游戏服务器搭建详细教程

    Minecraft这是原版英文名称,在中国大陆被译为<我的世界>,这款游戏很火爆.台湾的很多小伙伴也在玩,其译名为<我的创世神>.现在这款游戏在国内已经被网易代理了.因为这款游 ...

最新文章

  1. Unity空间射击游戏开发教程
  2. 服务被干爆了!竟然是日志的锅!!
  3. 前端进阶(三) webpack处理vue以及vue-cli脚手架环境
  4. Unity提出ProtoRes模型:稀疏可变的输入也能构建完整人体姿态
  5. 死锁产生的4个必要条件,如何检测,解除死锁
  6. Eclipse中设置在创建新类时自动生成注释的方法
  7. scanf 用法大全
  8. 手机、平板、PC与智能电视实现数据大统一
  9. 曲线拟合的线性最小二乘法
  10. boot spring 跨域注解_每日一问学技术:@SpringBootApplication注解干了个啥?
  11. 什么叫pmt测试分析_圆偏振发光光谱仪——南方科技大学分析测试中心设备介绍第51期...
  12. 彻底弄懂jsonp原理及实现方法
  13. java内功 ---- jvm虚拟机原理总结,侧重于虚拟机类加载执行系统
  14. 百度之星作为座位调整java_百度之星程序设计大赛十周年算法合集20052014.PDF
  15. 形式化方法(一) 逻辑部分概念梳理
  16. Echarts图表的基本使用
  17. 深圳荣耀Java后端一面
  18. 金仓数据库 KingbaseES 客户端编程接口指南 - ODBC 驱动使用
  19. Can't load /root/.rnd into RNG
  20. 主机记录(A记录)是什么

热门文章

  1. 用C++写洛谷P1427小鱼的数字游戏
  2. 计算机主机usb插口松,台式电脑音频接口坏了or接触不良?用这两个方法轻松解决,还不需要花什么钱...
  3. 《雍正皇帝》文化专有词翻译策略的研究现状(纽马克)
  4. 解决OSS传输的文本文件网页打开乱码
  5. 一言不合就被“游戏毁掉”?!管管孩子,救救游戏吧!
  6. 【C++11】之 emplace_back() 与 push_back() 的区别
  7. 矩阵的生成及对角线运算
  8. php 加权计算公式,PHP计算加权平均数的方法
  9. 基于libtorch的Alexnet深度学习网络实现——Cifar-10数据集分类(提升准确率)
  10. 网路连接配置和DNS服务?解决无线网卡连接WIFI问题(硬件和驱动没问题)?