017 domain names using local project

1. unified environment

We now have access to the page using: HTTP: // localhost: 9001

 

Actual development, have different environments:

 

  • Development Environment: own computer

  • Test environment: to provide environmental testers used

  • Pre-publishing environments: data generation and data is consistent environment, run the latest project code into the test

  • Production environment: the final release of the project on-line environment

 

If you use different environments for different ip to access, there may be some problems. In order to ensure a consistent environment for all, we will use the domain name in a variety of environments to visit.

We will use the following domain names:

  • Primary Domain Name is: www.leyou.com , leyou.com

  • Management domain: manage.leyou.com

  • Gateway domain: api.leyou.com

2. DNS

 

A domain name will be resolved to one or more ip. This generally involves two steps:

(1) Local DNS

The browser will first look in hosts file to the machine's IP address, domain name mapping, and if found return IP, did not find the domain name server to resolve, usually resolved locally will fail, because the default this file is empty.

  • hosts file addresses under Windows: C: / Windows / System32 / drivers / etc / hosts

  • The path where the hosts file under Linux: / etc / hosts

style:

# My hosts
127.0.0.1 localhost

(2) to resolve domain name server

Local resolution fails, it will resolve the domain name server, domain name server is a network computer, which records all the registered domain names and ip mapping relationship record, usually as long as the domain name is correct and filing through, will be able to find.

3. solve DNS problem

I can not go buy a domain name, so I can fake the local hosts file to achieve DNS resolution. Modify the local host is:

 

127.0.0.1 api.leyou.com
127.0.0.1 manage.leyou.com

This realization of the relationship between domain names mapped.

Every time looking for the hosts file on the C drive and change is very troublesome, it is recommended a quick modification host of tools.

 

Decompress, run the exe file, the effect of:

We added two mapping relationship (separated by a space):

  • 127.0.0.1 api.leyou.com: our gateway Zuul

  • 127.0.0.1 manage.leyou.com: Our back-end system address

By domain names:

The reason: We configured the access path to the project, although ip manage.leyou.com map is 127.0.0.1, but webpack will verify whether the host configuration.

Cancellation host validation in webpack.dev.conf.js in:disableHostCheck: true

 

Re-run in the terminal console , refresh your browser:npm run dev

 4.nginx solve port problems

 

Domain name issue is resolved, but now want to access the page background, had to add their own ports: HTTP: //manage.leyou.com: 9001 / .

 

This is not the elegance. We hope that direct access to the domain name: HTTP: //manage.leyou.com . In this case the default port is 80, how can we transfer request to 9001 port it?

 

Here it is necessary to use a reverse proxy tool: Nginx

(1) Nginx Overview

 

nginx as a web server, but more often, we take it as a gateway, a gateway because it has the necessary features:

  • Reverse Proxy

  • Load Balancing

  • Dynamic Routing

  • Request Filtering

(2) nginx as a web server

Web server sub-categories:

  • web application server, such as: Tomcat, Resin, Jetty

  • web服务器,如:Apache 服务器、Nginx、IIS

区分:web服务器不能解析jsp等页面,只能处理js、css、html等静态资源。 并发:web服务器的并发能力远高于web应用服务器。

 (3)nginx作为反向代理

什么是反向代理?

  • 代理:通过客户机的配置,实现让一台服务器代理客户机,客户的所有请求都交给代理服务器处理。

  • 反向代理:用一台服务器,代理真实服务器,用户访问时,不再是访问真实服务器,而是代理服务器。

nginx可以当做反向代理服务器来使用:

  • 我们需要提前在nginx中配置好反向代理的规则,不同的请求,交给不同的真实服务器处理

  • 当请求到达nginx,nginx会根据已经定义的规则进行请求的转发,从而实现路由功能

利用反向代理,就可以解决我们前面所说的端口问题,如图

 

 

 

Guess you like

Origin www.cnblogs.com/luckyplj/p/11484833.html