Using nginx to reverse proxy multiple Tomcats under an ip

Keywords: Nginx less

Links to the original text: https://my.oschina.net/u/2529405/blog/663615

Question: After using Aliyun host and domain name, it can only resolve to 80 ports of IP by default. It is not valid to configure secondary domain name to point to the same ip.

Solution: Using nginx reverse proxy server for reverse proxy
Principle: using the nginx upstream mechanism, nginx can become a reverse proxy server.
The configuration file is as follows
 1 worker_processes 1;
 2 error_log logs/error.log;
 3 pid logs/nginx.pid;
 4 worker_rlimit_nofile 65535;
 5 events {
 6     use epoll;
 7     worker_connections 65535;
 8 }
 9 http {
10     include mime.types;
11     default_type application/octet-stream;
12     sendfile on;
13     keepalive_timeout 65;
14     client_max_body_size 50m; #Buffer proxy buffers the maximum number of bytes requested by the client, which can be understood as saving them locally and then passing them on to the user
15     client_body_buffer_size 256k;
16     client_header_timeout 3m;
17     client_body_timeout 3m;
18     send_timeout 3m;
19     proxy_connect_timeout 300s; #nginx connection timeout with back-end server (proxy connection timeout)
20     proxy_read_timeout 300s; #When the connection is successful, the response time of the back-end server (the agent receives the timeout)
21     proxy_send_timeout 300s;
22     proxy_buffer_size 64k; #Set up the size of the buffer where the proxy server (nginx) saves user header information
23     proxy_buffers 4 32k; #The proxy_buffers buffer, if the average page size is less than 32k, is set as follows
24     proxy_busy_buffers_size 64k; #Buffer size under high load( proxy_buffers*2)
25     proxy_temp_file_write_size 64k; #Setting the cache folder size, greater than this value, will pass requests from the upstream server without buffering to disk
26     proxy_ignore_client_abort on; #Proxy is not allowed to actively close the connection
27     upstream www.kite.live {
28                         server localhost:8080;
29     }
30     upstream pan.kite.live {
31                         server localhost:8081;
32     }
33 
34    server {
35         listen       80;
36         server_name  pan.kite.live;
37                 location / {
38             proxy_set_header   Host             $host;
39                         proxy_set_header   X-Real-IP        $remote_addr;
40                         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
41                         proxy_pass http://pan.kite.live;
42                 }
43     }
44     server {
45     listen       80;
46     server_name  www.kite.live;
47         location / {
48                 proxy_set_header   Host             $host;
49                 proxy_set_header   X-Real-IP        $remote_addr;
50                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
51                 proxy_pass http://www.kite.live;
52                 }
53     }
54 }

 

Reproduced in: https://my.oschina.net/u/2529405/blog/663615

Posted by frost on Thu, 03 Oct 2019 21:17:47 -0700