It ’s enough to ask Nginx for this interview

1. What is the role of Nginx?

1. Reverse proxy
2. Load balancing
3. Microservice gateway entrance solution cross-domain
4. Static resource server
5. Protection of our website, security strategy, fuse, prevent ddos ​​attack, current limit;
6. Failover

2. DNS domain name resolution process

It is configured in the local host file. When the browser is accessed, it is first found in the local host file. If the domain name is not configured locally, go directly to the current operation to obtain the ip address

Third, the difference between forward proxy and reverse proxy

  • Forward agent is to hide user behavior, such as user access to member integrated platform, users do not know whether they have access to Tencent video or iQiyi
  • The reverse proxy hides the real server,

4. What are the causes of cross-domain issues?

Browser's homology strategy

  • Same agreement
  • Domain name is the same
  • Same port

5. What problems will exist in the server cluster?

1. Distributed session consistency problem, you can use spring-session framework or Token instead to solve
2. Distributed task scheduling repeated execution, distributed task scheduling platform xxl-job
3. Distributed log collection problem elk + kafka log collection

6. Nginx's five load balancing algorithms?

1. Default polling: traversal
2. Weight: server access ratio
3. Hash ip_hash: each request is allocated according to the hash result of the access ip, so that each visitor fixedly accesses a back-end server, which can solve the problem of session
4. Response Time fair (third party): distribute the request according to the response time of the back-end server, priority is given to short response time
5, url_hash (third party): distribute the request according to the hash result of accessing the url, so that each url is directed to the same Backend server, which is more effective when the backend server is cached

7. What is the difference between soft load and hard load?

Soft = software: use software for load balancing, such as nginx
hard = hardware: use certain facilities to achieve load balancing

8. Seven solutions to cross-domain issues?

1. Set the response header to allow cross-domain: response.setHeader ("Access-Control-Allow-Origin", "*");
2. Use jsonp to solve, the disadvantage: only able to send get requests, it is very troublesome, not recommended
3. Nginx implements the domain name and port number of a unified interface. Nginx uses the same domain name to solve cross-domain problems, uses different locations, forwards to a specified server
4, uses a gateway in microservices to solve cross-domain problems
5, uses HttpClient to implement forwarding, and Nginx The same as the proxy principle, httpClient does not have cross-domain behavior
6, SpringBoot cross-domain annotation @CrossOrign
7, vue

Nine, the difference between Lvs and nginx load balancing?

  • Lvs is to manage the Nginx cluster, the fourth layer of load balancing, based on Tcp ip and port number to achieve load balancing, compare the bottom
  • Nginx is to manage our server cluster, layer 7 load balancing, and load balancing to the http protocol

Ten, Lvs + KeepAlived + Nginx to achieve high availability

  • Lvs: nginx cluster coordinator, virtual VIP, for Nginx load balancing, client requests first reach the lvs virtual VIP address, and then load balancing is forwarded to the Nginx server through lvs, and then Nginx is forwarded to the real upstream server, setting the virtual VIP specification, Must be on the same network segment 192.168.212.xxx and cannot be occupied
  • KeepAlived: Extend Lvs, perform heartbeat detection on Nginx, and restart when downtime. Each Nginx needs to install a KeepAlived. In the case of multiple restart failures, notify the operation and maintenance personnel by email to manually handle (alarm)
  • Nginx: manage upstream servers

11. How to solve the situation when both the main and standby Nginx are down?

1. Restart is possible, very low
2. Use lvs heartbeat detection, regular ping ip: port number, use keepAlived to restart

Twelve, nginx dynamic and static separation architecture mode

  • Static resources are placed on the nignx server and dynamically placed on the tomcat server, so that the throughput is relatively high
  • Client-> nginx-> Client

Thirteen, traditional model

  • Static and dynamic are on the tomcat server, low throughput
  • Client-> nginx-> tomcat static resource-> nginx-> client

14. Two methods to achieve dynamic and static separation based on nginx

1. Use the location in nginx.conf to determine the prefix
127.0.0.1/static to reverse proxy to a static file
2. Use the location in nginx.conf to determine the suffix
~ (png | jpg | gif)

Fifteen, the reason for the slow loading of the webpage and its solution

  • In a website, static resources take up bandwidth, the pictures are larger, the code takes up less, and the speed and distance of bandwidth transmission are all related.
  • If there are 500 people accessing the website at the same time, and the concurrent volume reaches 500 people, the current limiting and fusing mechanism should be done, otherwise the server is prone to problems
  • Insufficient bandwidth. If the picture is too large, it is recommended to split a large picture into N small pictures and store them in segments
  • Large amount of concurrency

For example: when dynamic and static resources are placed on the same server, dynamic resources are 10kb, static resources are 590kb,
bandwidth is 1mbps, transmission efficiency is 128kb / m 1024➗8 = 128,
rendering webpage needs 600kb➗128kb / s = 4.7s

Solution:
1. Increase the bandwidth, but not cure the symptoms
, 2. Separate dynamic and static resources

16. Why is it very efficient to store static resources on a third-party server?

1. Cloud server signing bandwidth is calculated by T.
2. CDN (Content Distribution Network) content distribution. The ability to cache static resources to nodes across the country can reduce the distance between the client and CDN bandwidth. Improve the response speed; Improve access speed), each customer visits a different area, when a server visits too much, go back to visit the idle server, a bit like load balancing

  • Static resources are physically stored in the Qiniu Cloud (persisted to hard disk), other nodes are cached and temporarily stored

17. Three ways to compress static files

1. Online js formatting, manual compression, uncomment, make a line
2. Maven packaging, it will automatically compress, generate .min file
3. Use nginx, put it in the server in nginx.conf, it will be automatically compressed when accessed , Compression format, for example, function becomes A, var becomes B, and it is returned to the browser. The browser recognizes A as a function, which reduces a lot of bandwidth transmission, and selects a replacement with a relatively large number of repetitions, and does not repeat compression for each access , Cached.
Disadvantages: this is very cpu resource consuming, has to deal with many things, consume memory

18. http protocol returns 304, access cache

The browser will cache the static resource when it is accessed for the first time, and access the cached static resource status code 304 when it is accessed for the second time. When the cache is cleared or the static file is modified, the cache will be regenerated and the status code becomes 200. The key in the cache is url, the value is the content of the cache, and nginx also comes with its own cache

Look down level by level, if you have a cache, you wo n’t look down

  • Client cache (browser cache)-> cdn cache (Qiniu cloud cache)-> Nginx cache-> jvm cache-> redis distributed cache-> database

Nineteen, nginx cache and server real data consistency problem

1. Use lua to solve, high efficiency
2. Add version number or time stamp, so that each time the url will be different, it is not recommended
3. Delete the cache

Twenty, nginx failover

 如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。  
 proxy_next_upstream http_502 http_504 error timeout invalid_header;  
 proxy_cache cache_one;  

Twenty-one, other

1. Nginx and the real server are in the same LAN, but not in the same server.
2. In the case of only entering the domain name, the default access is port 80
3. netstat -aon | findstr “80” See who is occupying the port number
4 1. The server cluster is to solve high concurrency and high availability.
5. The distributed transaction problem does not belong to the problem in the node cluster.
6. The upstream server == real server
7. The port number 80 is occupied: https://www.cnblogs.com /Noul/p/10174061.html
8. nginx is written in c language 9,
502, nginx forwarding fails, is being released
10. nginx implements a cluster, one master and one backup, when you want to publish new content, publish through the backup machine, and then stop When the host computer is turned off, the standby machine becomes the host computer. If it is posted directly on the host, you need to stop the host, update, restart, bad.
11. Alibaba Cloud server does not support virtual VIP technology, additional mai is required
12. An exception occurs when a user accesses a web address, intercepts the exception through aop, calls the WeChat message interface and sends it to the developer
13, oos object storage
14, third-party Qiniu The static resource server is better than Alibaba Cloud. It is a static resource server . Alibaba Cloud oos is also a static resource server.
15. The most expensive is the bandwidth, then the IP address
16. The internal network does not require bandwidth transmission. , The speed is particularly fast, the external network requires bandwidth transmission17
, large memory, you can open many software (multiple processes) at the same time, large bandwidth, high transmission efficiency, large core, fast processing speed
18, 8 trillion pictures are compressed into 2 by technical means The megabyte will become fuzzy, it is better to store it in sections
19. Redis and database cache consistency issues, mq subscription binlog synchronization data consistency issues, jvm and redis maintain consistency issues

Published 53 original articles · Likes2 · Visits 1869

Guess you like

Origin blog.csdn.net/qq_42972645/article/details/104626847