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
server {
listen 80;
# domain name
server_name maibao.cms.com;
location / {
The IP address and port number of the proxy
Proxy_pass http://127.0.0.1:8082/;
# agent connection timeout in milliseconds
proxy_connect_timeout 600;
Read resource timeout for agent in milliseconds
proxy_read_timeout 600;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
You can also use the following methods:
Copy the code
upstream tomcatserver_cms{
Server 127.0.0.1:8082;
}
server {
listen 80;
server_name maibao.cms.com;
location / {
proxy_pass http://tomcatserver_cms/;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
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