Nginx request proxy and node request proxy

nginx:

    server {
        #SSL 默认访问端口号为 443
        listen 443 ssl; 
        server_name  gpt.xutongbao.top;
        ssl_certificate         /temp/ssl/gpt.xutongbao.top/gpt.xutongbao.top.crt;   # nginx的ssl证书文件
        ssl_certificate_key     /temp/ssl/gpt.xutongbao.top/gpt.xutongbao.top.key;  # nginx的ssl证书验证密码


        #配置根目录
        location / {
            #root   html;
            root    /temp/yuyingGpt;
            index  index.html index.htm;
            add_header Content-Security-Policy upgrade-insecure-requests;

        }

        # 匹配cdn开头的请求,实际转发的请求去掉多余的cdn这三个字母
        location ^~/cdn/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://hlzc-static.xutongbao.top/;
        }

        # 匹配api开头的请求,实际转发的请求保api这三个字母
        location /api/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://yuying-api.xutongbao.top;
        }
    }  

node:

const { createProxyMiddleware } = require('http-proxy-middleware')

module.exports = function (app) {
  //通过代理解决跨域
  app.use(
    '/zlhx',
    createProxyMiddleware({
      //target: 'http://test-zhiliao.gongzuoshouji.cn',
      target: 'http://api-zlhx.gongzuoshouji.cn',
      changeOrigin: true,
    })
  )
  //匹配api开头的请求,实际转发的请求保api这三个字母
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:85',
      changeOrigin: true,
    })
  )
  //匹配sslCnd开头的请求,实际转发的请求去掉多余的sslCnd这六个字母
  app.use(
    '/sslCnd',
    createProxyMiddleware({
      target: 'http://cdn.xutongbao.top',
      changeOrigin: true,
      pathRewrite: {
        "^/sslCnd": ""
      }
    })
  )
}

1. What is Nginx?

Nginx is a high-performance HTTP and reverse proxy web server that also provides IMAP/POP3/SMTP services. Nginx is a lightweight web server/reverse proxy server and email (IMAP/POP3/SMTP) proxy server. The characteristics of Nginx are: it occupies less memory and has strong concurrency capability.

Nginx is specially developed for performance optimization. Performance is the most important consideration. It pays great attention to efficiency. In fact, the concurrency capability of Nginx is better than other web servers of the same type, and it can support up to 50,000 concurrent connection responses.

Concept: The reverse proxy server is located between the user and the target server, but for the user, the reverse proxy server is equivalent to the target server, that is, the user can directly access the reverse proxy server to obtain the resources of the target server.

The reverse proxy, in fact, is unaware of the proxy for the client, because the client can access it without any configuration.

Process: In reverse proxy, we only need to send the request to the reverse proxy server. After the reverse proxy server selects the target server to obtain the data, it returns the data to the client. At this time, the reverse proxy server and the target server are in the outside world. It seems that it is a server, and what is exposed is a proxy server, which hides the IP address of the real server.

Reference link:

https://chat.xutongbao.top/

Guess you like

Origin blog.csdn.net/xutongbao/article/details/131702144