preface

A project from development to online will have different environment, such as the development environment, test environment, pre-release environment, production environment, such as different environment project access address is different, different access address also can cause some problems, in order to avoid these problems, can make the different environment of access to the same address, this can be done by configuring the domain name.

1. Configure the mapping between the access address and domain name in the Windows development environment

1, find the hosts file under Windows, windows10 in C:\Windows\System32\drivers\etc directory;

2. Open the hosts file with administrator permission, because you need administrator permission to save the file.

3. Add the mapping between the access address and domain name in the hosts file, for example, 127.0.0.1 maibao.cms.com. If the project has been deployed on a remote server, change 127.0.0.1 to the address of the remote server.

4, after saving can be accessed through the domain name, such as: Maibao.cms.com :8082, but because an application is usually served by multiple internal servers, it is impossible for users to use ports for access, and the server itself should decide which server to use to provide services to users, which requires the use of reverse proxy.

Install nginx in Windows development environment and reverse proxy

Download: nginx.org/en/download…

1. Decompress nginx-1.14.0.zip to a directory where it can be used.

2. In the conf directory of the decompressed directory, find nginx.conf and change the IP address and port number of the server agent.

3. Modify the server as follows:

 
Copy the code
  1. server {
  2.         listen       80;
  3. # domain name
  4.         server_name  maibao.cms.com;
  5.  
  6.         location / {
  7. The IP address and port number of the proxy
  8. Proxy_pass http://127.0.0.1:8082/;
  9. # agent connection timeout in milliseconds
  10.             proxy_connect_timeout 600;
  11. Read resource timeout for agent in milliseconds
  12.             proxy_read_timeout 600;
  13.         }
  14.  
  15.         error_page   500 502 503 504  /50x.html;
  16.         location = /50x.html {
  17.             root   html;
  18.         }
  19.     }

You can also use the following methods:

 
Copy the code
  1. upstream tomcatserver_cms{
  2. Server 127.0.0.1:8082;
  3.     }
  4.  
  5.     server {
  6.         listen       80;
  7.         server_name  maibao.cms.com;
  8.  
  9.         location / {
  10.             proxy_pass http://tomcatserver_cms/;
  11.         proxy_connect_timeout 600;
  12.         proxy_read_timeout 600;
  13.         }
  14.  
  15.         error_page   500 502 503 504  /50x.html;
  16.         location = /50x.html {
  17.             root   html;
  18.         }
  19.     }

4, Start nginx command in nginx root directory: start nginx;

5. Check whether nginx is started

If nginx is running, nginx has stopped. If nginx is running, nginx has stopped

(2) to see if port 80 launch, see the command is: netstat ano | findstr searches: 80;

6, modify the configuration file and restart the nginx command: nginx -s reload;

7, stop nginx command: nginx -s stop