Virtual machines deployed on other hosts in the LAN access project

  Busy recently, a long time did not write a blog, squeeze point in time today to write about, as this time it encountered a problem

  First, linux bloggers are using the Ubuntu16.04:

  

   Secondly, there are two hosts within a LAN, and the IP are 192.168.28.94 192.168.28.213, 94 and 213 respectively, referred to hereinafter, visible both hosts on the same network segment, can be connected, you can ping each try, if not ping pass, look no on whether the network cable is connected, there is no firewall related

   Then our virtual machine address is 192.168.209.129, hereinafter referred to as 129, a virtual machine running on a 213, and 213 virtual machines can ping the host is, if the ping fails, look virtual machines and 213 firewall has not related, our 94 Rom virtual machine, naturally ping nowhere

   Well, now the problem is to get the project on the 94 host access to the virtual machine, where the use .net core project, for example, may also be other items such as java.python etc. can be

   To solve this problem, I think so, and 94 can be connected to the 213, 213 and 129 can be connected to the virtual machine, you can do a reverse proxy on the host computer 213, so that request is forwarded to the virtual machine, with this ideas, we can start with the

  First, install dotnet, .net core projects run

  If java, is to install the JDK, if it is to install python python compiler up, dotnet SDK installation can refer to my previous blog: https://www.cnblogs.com/shanfeng1000/p/11065804.html

  

  After dotnet installed, we can run the .net core project, if not, you can generate a direct:

  Enter dotnet new mvc mvc will be able to create a project, remember to create a directory to store before you create, such as where to create a demo catalog

  

  Use dotnet run command to run the project on it, but we do not use this way, because he will be up and running in default port 5000 http and https port of 5001, and when the visit http port 5000, will be automatically redirected to the https 5001 port, of course, we can start to modify settings in launchSettings.json under the Properties directory of the project, however, we retain the integrity of the project, other methods

  The first to use dotnet build build the project:

  

  Generation is a simple package, the executable file under the sub-project generate bin / Debug / netcoreapp2.2 directory, as in the following demo.dll

  

   Then executed in bin / Debug / netcoreapp2.2 directory dotnet demo.dll --server.urls http: // localhost: 5050 &, note that the command followed by the & symbol, indicating that the command in the background, without blockage causes the current shell , .net core default port 5000, 5050 changed here, this can easily

   If not the next bin / Debug / netcoreapp2.2 directory, then we would take the appropriate path before demo.dll

  

   Now we can use on a virtual machine: curl http: // localhost: 5050 visits

   When we browser on the host 213 to access the project: http: //192.168.209.129: 5050, but not to visit, this is because we listen interface is http: // localhost: 5050, so of course access on 213 less than a, if you want access to 213, localhost startup items above will be able to change *

  如:dotnet demo.dll  --server.urls http://*:5050

  Second, the use nginx reverse proxy to do

   nginx installation can refer to my blog: https://www.cnblogs.com/shanfeng1000/p/11063851.html

   Here, for simplicity, directly on the use of sudo apt install nginx be installed

  After the installation is complete, enter /etc/nginx/conf.d, execute sudo cp ../sites-available/default demo.conf copy of the default configuration file in the current directory (conf.d), and then specify sudo vim demo .conf enter edit

  

   Find the server node, modified as follows, .net core because port 5000 is the default port used to avoid future conflict, so here we use port 50000:

  

  In the server node found server_name node, modify the service name, are free, as used herein to Demo, and then find the location server node in the node, modified as follows:

  

    Note that the above configuration are ending semicolon

  Now after exiting, use the command sudo nginx open nginx, or if you have opened, use sudo nginx -s reload reload configuration on it, you can also pre-reload, first try sudo nginx -t to test the configuration is correct

   

   In addition, notes that, if run, appears: nginx: [error] open () "/run/nginx.pid" failed (2: No such file or directory)

  This is because the master process has been closed. Direct use sudo nginx command to enable it:

  

  Now you can use on the 213 hosts on the browser: http: //192.168.209.129: 50000 / visit

 

     

  Third, do a reverse proxy using IIS

   213 is the windows system, using another tool to do a reverse proxy is also OK, here using IIS

  First search in the Start menu IIS:

  

  If not, start = open "operation, the input control, or win + r runs, the input control

   

  Open the Control Panel, select [Programs and Features], and then on the left select [Enable Windows features on or off]

   

   After the pop-up window check Internet Information Services:

  

  Then determine the wait can be completed, in the Start menu search IIS will be able to search, this step may need to restart your computer to take effect

  Open the IIS, we also need to install ARR, in order to use a reverse proxy functionality:

  

   Arr Download: https://www.iis.net/downloads/microsoft/application-request-routing

  Arr After installing the need to restart IIS to take effect, type in cmd iisreset to restart IIS console, and then open the IIS Manager will have the image above Application Request Routing Cache, we click into the select zip code Server Proxy settings

  

 

   Then check Enable Proxy, other basically do not change, of course, if you need to, you can also modify, then click on the [Application] on it,

  

 

  Right then left the site entry, the new website,

   

  After the new good, and then click on the site built into the URL rewriting:

  

 

  In the [Inbound Rules] right, select [New Rule] = "[blank] rule, free to fill in the name, input mode ^ (. *)

   

  Open conditions, addition conditions, {HTTP_HOST} in input condition input and enter ^ 192.168.28.213 in mode: $ 50000, that is to say, all of the requests will be blocked 192.168.28.213:50000 forward, click OK

   

   Then modify the operation of the following type rewrite operation, is rewritten Url: http: //192.168.209.129: 50000 / {R: 1}, and finally clicking on it the right applications

  

   Pressing the above steps, enter the Demo site again next Url rewriting is like this

  

   And then start the Web site:

  

   Then open your browser, you can access the local port 50000, and also in other LAN port 213 through 50000 of access to project virtual machines on the 213, such as access to over 94: http: //192.168.28.213: 50000

   Finally, draw a diagram schematically:

  

 

 

   

 

Guess you like

Origin www.cnblogs.com/shanfeng1000/p/11465959.html