The domain name filing for a week was finally done yesterday.

Songo’s first thought was to deploy the minions and V clans, and I know a lot of guys can’t wait.

1. I used to go online

In fact, when these two projects were just completed, I deployed them to the server to help my friends better view the effect. But that is a foreign server, buy foreign server, basically be disliking domestic put on record trouble, also have the reason that other everybody understands of course.

Foreign servers have convenient places, but also have a lot of inconvenience, such as network instability, the risk of losing contact at any time. So at the beginning of 2018, although I deployed these two projects on the server, many partners had poor access experience, mainly due to network problems. Later, after several rounds of siege and counter-siege, the server was completely disconnected from Songko.

After the loss of contact, I was too busy to do anything about it, so the micro personnel and V tribe members could not check the effect online for a long time.

2. Go online again

Recently because of some other plans, so I bought Ali cloud service, after the completion of the record, after all things are done, I want to deploy the micro personnel and V tribe first, so that everyone can see the effect.

I first planned two secondary domain names:

  • vblog.itboyhub.com
  • vhr.itboyhub.com

These two secondary domain names are used to deploy the V tribe and micro personnel respectively.

You can view the effect from these two addresses:

Micro personnel

V tribe

In order to ensure that every friend can see the full demonstration effect, to prevent some careless friend to empty all data, leading to other friend what all can’t see, I just opened a demo account queries and part of the field update permissions, so everybody in view the demonstration effect, there may be some involving increased bowdlerize failed to perform operations, no offense, After you have deployed the project to run locally, you can see the full effect.

3. The skill tree

Now that I’m there, LET me tell you a little bit about how these two deployments are implemented.

3.1 Deployment Scheme Selection

As you know, when the front and back end are deployed separately, we have two different solutions:

  • One is to package the front-end project, compile it, and put it into a back-end project (such as the Spring Boot project’ssrc/main/resources/staticDirectory)
  • The other is to use Nginx to deploy the static resources packaged in the front end, while the back-end alone only needs to provide interfaces.

In corporate projects, we tend to do the latter. But for the sake of ease of deployment in Songko, I adopted the first option. (I’ll talk to you later about the second deployment.)

3.2 Domain Name Mapping

Domain name mapping this simple, login Ali cloud background, add two A records can be.

3.3 Starting Spring Boot

Then start the two projects respectively. The default ports of the two projects are 8081 and 8082 respectively. Command:

nohup java -jar vblog.jar > vblog.log &
nohup java -jar vhr.jar > vhr.log &
Copy the code

Write the run logs of the two projects to the vblog.log and vhr.log files respectively.

After successful startup, we can access the two projects through itboyhub.com:8081 and itboyhub.com:8082 respectively. I want to access it through a secondary domain name, and I want to access it through port 80, using Nginx.

Pay attention to

After the startup is complete, you need to log in to ali Cloud background to confirm that port 8081 and port 8082 are enabled.

3.4 Nginx configuration

For the basic usage of Nginx, you can refer to this old article by Songo:

  • Nginx Minimalism tutorial!

Here we will focus on Nginx configuration.

Since there are two secondary domain names and other domain names will be configured on the server in the future, the domain name must be able to be dynamically resolved. Therefore, the specific configuration is as follows:

server {
    listen       80;
    server_name  *.itboyhub.com;

    if ($http_host~ *"^ (. *?) \.itboyhub\.com$") {
            set $domain The $1;
    }
    # Other configuration...
}
Copy the code
  • The first port to listen on is 80
  • Secondary domain names use a wildcard character*Instead of
  • Next in the if statement, through the regular expression to extract the name of the secondary domain name, to the variable $domain, for later use.

Next, configure the forwarding rule:

location / {
  if ($domain~ *"vhr") {
    proxy_pass http://itboyhub.com:8082;
  }
  if ($domain~ *"vblog") {
    proxy_pass http://itboyhub.com:8081;
  }
  
  tcp_nodelay     on;
  proxy_set_header Host            $host;
  proxy_set_header X-Real-IP       $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  index index.html;
}
Copy the code
  • When the $domain defined contains VHR characters, the request is forwarded to itboyhub.com:8082
  • When the $domain defined contains vblog characters, the request is forwarded to itboyhub.com:8081
  • Finally, configure the proxy server to transmit user information to real Server

On the other hand, since the default backend home page is /index.html, if a user goes directly to vblog.itboyhub.com or vhr.itboyhub.com, it will be blocked by the permission management mechanism (automatically redirected to /login_p), so, If the user access address does not contain /index.html, /index.html is automatically added. The configuration is as follows:

location /login_p {
   if ($domain~ *"vhr") {
     rewrite ^/(.*)$ http://vhr.itboyhub.com/index.html permanent;
   }
   if ($domain~ *"vblog") { rewrite ^/(.*)$ http://vblog.itboyhub.com/index.html permanent; }}Copy the code

Note that this line is configured before location /, and the two ifs here have the same meaning as the previous ones.

Nginx configuration file: nginx configuration file: nginx.conf

Next we can access the two open source projects through the following two secondary domain names, friends hurry to try.

  • vblog.itboyhub.com
  • vhr.itboyhub.com

4. Conclusion

Finally, let’s give these two open source projects a little extra credit:

  • github.com/lenve/vhr
  • github.com/lenve/VBlog

If you want to learn about the Spring Boot + Vue front and back separation project, these two are great resources. The V tribe is easier, both technically and professionally, so if you’re new to it, look at the V tribe first. Micro personnel although slightly complex, but fortunately songge with a complete development document, according to the development document, I believe that we can understand most of the functions. The documentation is as follows:

If you encounter problems in the process of deployment, you can also refer to the deployment video of Zongo’s hand in hand:

  • Micro personnel project deployment video tutorial

Well, that’s all for this article. If you have any questions, please leave a comment.

Pay attention to the public account [Jiangnan little Rain], focus on Spring Boot+ micro service and front and back end separation and other full stack technology, regular video tutorial sharing, after attention to reply to Java, get Songko for you carefully prepared Java dry goods!