当前位置:网站首页>10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects

10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects

2022-06-13 03:59:00 Smoothzjc

Hello everyone , I am a Smooth, A sophomore front-end enthusiast , The goal is to become a front-end development engineer

Configuring subdomains allows you to deploy multiple projects on one server at the same time

This article will explain in detail how to configure subdomains so that you can deploy multiple projects on one server at the same time , A tutorial that novices can understand, haha

demand

There are the following requirements :

I have a domain name zhangjiancong.top, I want to put some on it web application , Namely

  • Personal blog :myblog.zhangjiancong.top
  • Entertainment :xxx.zhangjiancong.top

One way is to nginx Of document myblog、xxx Catalog , The access method is zhangjiancong.top/myblog

zhangjiancong.top/xxx

But this has several disadvantages

  1. some web The application itself may not support non root directory access , Resulting in unavailability
  2. Because each application may need to location Special configuration of , These applications are not in the root path ,location Configuration may be different , More complicated
  3. Not cool enough , Too ugly

Need make myblog、xxx Each has its own subdomain (myblog.zhangjiancong.top、xxx.zhangjiancong.top), You can do that :

  1. At the domain name service provider , Add one more CNAME Record , Point the subdomain name to be configured to the host name corresponding to the root domain .
  2. Then modify it in the pagoda interface Nginx To configure
  3. Add new site

As follows

To configure

1. add to CNAME Record

This is alicloud , So Alibaba cloud is used as an example , No matter what service provider , Open the domain name resolution interface

Enter the domain name resolution interface
image.png


Click Add record
image.png

Configuration instructions

CNAME Record

When will it be used CNAME Record ?

[ If you need to point a domain name to another domain name , Provided by another domain name ip Address , You need to add CNAME Record ]
Most commonly used to CNAME This includes : do CDN, Configure subdomains

CNAME Notes on adding records

Remember to change the column "analysis line" to Default , China Unicom will only give an example to illustrate the role of this configuration item
image.png

  • Record type : choice CNAME

  • Host record : Fill in subdomain name ( For example, you need to add myblog.zhangjiancong.top Parsing , Just fill in the host record myblog that will do ; If you add zhangjiancong.top Parsing Parsing , The host record is left blank , The system will automatically fill in a “@” To input box ).

  • Analytic circuit : The default can be ( If the default is not selected, some specific users will not be able to resolve ; The function in the above figure is : All users except Unicom users can normally parse )

  • Record value :CNAME Domain name pointed to , You can only fill in the domain name , After the record is generated, the domain name will be automatically followed by a “.”, It's normal

  • TTL: When adding, the system will automatically generate , The default is 600 second (TTL For cache time , The smaller the numerical , The faster the change takes effect ).

Click ok

2. modify Nginx The configuration file

Find this item in the pagoda interface

image.png


Find the configuration entry
image.png

For configuration files server Modify the fields as shown in the figure above

  • Because my main domain name is another resource of mine loaf-community, So I $doc The initial value is "loaf-community", Otherwise "" that will do
  • if To match rules ,root Corresponding path resources for the server , My resources are all on /www/wwwroot/ Under the directory of , You can configure it according to the real path of your server
#  Set subdomain directory 
set $doc "loaf-community";
if ($host ~ ^(\w+)\.zhangjiancong\.top) {
    set $doc $1;
}

#  Set the corresponding... Of the domain name at this time root
root /www/wwwroot/$doc;

The advantage of doing so is , Then add a subdomain name , As long as I'm in /www/wwwroot Create a new subdirectory in the directory to put the new items , Take the subdomain name as the directory name , Then add a new word "domain name" in the domain name service provider CNAME The record is done , Very convenient .

image.png

3. Add new site

Find the entrance
image.png


Configure the subdomain name and its corresponding project resource path
image.png

After configuration, restart the server

After configuring the second step , After that, add new subdomains and items every time , Just go to step one and step three


The above is the whole content of this article


Last

Last , My name is Smooth, In this year 2022 In, I will also try my best to write more front-end tutorials , Looking forward to your attention ~

The latest document plan is Webpack as well as performance optimization Knowledge system
原网站

版权声明
本文为[Smoothzjc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280526484973.html