A preface.

Due to reasons known to all, inside the walls set up a website requires a lot of “process”, buy domain name, domain name registration, the server, do enterprise certification, customers often need to cooperate to submit various documents, the whole process go down about a month, also need to persuade customers to cooperate, among them “tired”, as a Freelancer you may feel. If every station has to do so, in fact, there are some communication costs and trust costs in it, for some relatively large projects, it is worth paying for this, but for ordinary enterprise stations or small display sites, we always hope to be able to quickly finish work (collect money) :), After all, we don’t want to spend too much time and energy explaining to customers why we need to submit business license, why we need the legal person to take photos and sign things like that, and we also need to accept the customers’ questioning eyes, and sometimes the project will fail because of this matter.

Ii. Solutions

In order to avoid filing, many people will choose foreign servers such as HK or The United States, but the problem is also known to us: slow speed, slow access to the front desk, slow backstage management upload, especially large picture upload browse…… If you are using a virtual host, you may not be able to FTP the source code. (TSK TSK… T_T) a chance to see a restful interface of some articles, I suddenly thought of, for the enterprise stand, need only background operation administrator, and basic it is at the front desk to visit, don’t need other functions, so if you can put the front end of the station in foreign countries, the backstage management part in domestic, and then use a restful interface for data transmission, Wouldn’t that solve all our problems? (In fact, there are some minor problems >_<), so I tried to separate the layout, the effect is good.

The advantages of this are:

  1. Only need to record their own server and domain name, other enterprise domain name and server do not need to record;
  2. The access speed is faster than the whole station to a foreign server

Principle of separate deployment

My deployment is like this. First, I will prepare a domestic Ali cloud ECS, which naturally requires a domestic domain name. Here is your-domain.com, LAMP environment, while the foreign virtual host is bound to the enterprise domain name www.qiye.com, as shown below:





The entire access process is as follows:

  1. Users access the enterprise sitewww.qiye.com, request web pages to the virtual host;
  2. If the virtual host needs to request some data to ECS (such as website name, website copyright information, etc.), it will send a request to ECS, if not directly jump to the fourth step;
  3. ECS returns Json information if there is a step 2 request;
  4. The virtual host returns the HTML to the user;
  5. User browsers request information from ECS via Ajax;
  6. ECS returns information.

It is not difficult to see that in fact we still need to put on record, but what we want to put on record is only our domain name and server, and the enterprise domain name of other customers no longer needs to put on record.

In the process, the second, third step is not necessary, website name, website copyright and other information can also be requested in the fifth step, and will be faster than the virtual host to ECS request (assuming visiting users in the country), because the virtual host and ECS separated by a wall 🙂 here the second, third step request, After the request is completed, the data will be embedded in HTML and then returned together. The request of step 5 and step 6 will use JS, such as ajax method of jquery to make the request.

Below I use pseudo code simulation to write 🙂

  1. Front end: You can use jquery to make Ajax requests and render data to a web page.
<div class="news-list"><div>

<script>
$(function(){
    $.get('api.your-domain.com/get/newslist',{
        page: 1
    }, function(data){
        if(data.success){
            $('.news-list').html(data); // If the request succeeds, it is rendered to the div layer. }})}); </script>Copy the code
  1. Background interface: here I provide two interfaces, one isapiGetNewsListGet the news list, one isapiGetNewsDetailGet a news story.
// Interface to get the news listfunction ApiGetNewsList(page=1){
    newsList = searchDB(page);
    returntoJSON(newsList); } // Interface to get news detailsfunction ApiGetNewsDetail(newsId){
    news = searchDB(newsId);
    return toJSON(news);
}
Copy the code

When someone accesses the interface, such as: api.your-domain.com/get/newslist?page=1, which returns a list of news items in JSON format, visit: Api.your-domain.com/get/newsdetail?newsid=2, return the json format news details, after obtaining the data the user’s browser, you can use js to render to the web page. Json data returned:

// Json data for the news list {1: {"title":"Headline 1"."createTime":"2020-02-02"."id": 2:1}, {"title":"Headline 2"."createTime":"2020-02-03"."id": 3:2}, {"title":"Headline 3"."createTime":"2020-02-04"."id":3},} // Json data for news details {1: {"title":"Headline 1"."createTime":"2020-02-02"."id": 1."content": "

Text....

"
}}Copy the code

4. Afterword.

You may ask, so domestic server and domain name also need to put on record? Yes, the domestic domain name your-domain.com and ECS server need to be put on record, this domain name and ECS are generally your own, you only need to prepare a case, while other customers’ enterprise domain name and server are abroad, do not need to put on record, so no matter how many enterprise sites, the customer website only need to get the interface from your ECS, The site is up and running. For website visitors, open the enterprise domain name, they will be able to access the enterprise network, as to how it works, I believe they will not open the F12 console to look at the source code of the web page 🙂 so far, the whole deployment and request process I also covered, finally, we will talk about the pros and cons of this.

Advantages:

  1. Only the case of their own domain name server, other enterprise site domain name server without record;
  2. Access speed is faster than the whole station to the foreign server;
  3. Foreign servers only need to store a small number of files (HTML, CSS, JS), the data are in China;

It says you only need to file once, which is one of the biggest advantages. Customers don’t need the hassle of filing, and they don’t have to endure slow access to foreign servers, so it’s worth the hassle.

The point is to be able to minimize data requests to virtual hosts,

Here’s an example: After the user browser gets the HTML, request the image information from the inside . At this time, the requested image is in the domestic server, and the user requests the list and news details to THE ECS through Ajax are also in the domestic. The speed will be much faster. The administrator of the site management is also in China, the upload speed will be very fast, and encounter front-end modification, we only need to upload some simple HTML and CSS, JS, naturally than the whole frame uploaded to the virtual host FTP on many faster.

Disadvantages:

In so doing, there are many shortcomings, first of all, your interface is exposed to the public, you can call other people also can call nature, your picture is also be cross domain access, so, if you are to do some shopping or security requirements of high standing, as it is not recommended to do so, here is only for ordinary enterprises stand in this way, after all, is only the display function, Others willing to call the news or products of the enterprise, help enterprise publicity, he le:) the second determine our background management is on the ECS, the landing, so enterprise management operations need to open the domestic domain names, the domestic domain name is usually your secondary domain name, the xu is not friendly to customers, also increase their doubts, Third, if the website not only need to provide information display, but also need to provide some login operations, this way is not very good, the solution is to use auth2.0 this authorization mode, but this undoubtedly increased our development costs. So if the customer requirements of the function more, or should be good to call the customer to record, he good, I good 🙂 above is my share, if there is any mistake, welcome to correct, if you have any better solution, so please tell me, thank you for reading 🙏