Nginx proxy service - Reverse Proxy

Nginx can proxy service

Forward proxy, for example, over the wall

Reverse Proxy

The difference between forward and reverse proxy

The difference is that the proxy object is not the same

Forward Proxy: proxy object is a client

Reverse Proxy: proxy object is a server

Configuration syntax

Syntax:proxy_pass URL;

Default:——

Context:location,if in location,limit_except

Reverse Proxy demonstration

Create a html file in the following directory / opt / app / code2 of

<html>
<head>
    <meta charset="utf-8">
    <title>imooc1</title>
</head>
<body style="">
    <h1>Welcome to www.test.joy.com</h1>
</body>
</html>

An increase of 2 profiles

realserver.conf

server {
    listen       8080;                # 使用8080的端口。此端口外网无法访问
    server_name  localhost www.test.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;



 #   location ~ \.(html|ico|txt|js|css|ttf)$ {
  #          # html不缓存
  #          add_header Cache-Control no-store;
           # root /data/node/dist;
   #     }

    location / {
        root   /opt/app/code2;    #访问的静态文件为此目录的test_proxy.html
        random_index on;
        index  index.html index.htm;
    }

下方省略....

fx_proxy.conf

server {
    listen       80;            # 80端口外网是可以访问的
    server_name  www.test.ab.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;



 #   location ~ \.(html|ico|txt|js|css|ttf)$ {
  #          # html不缓存
  #          add_header Cache-Control no-store;
           # root /data/node/dist;
   #     }

    location / {
        root   /opt/app/code;
        random_index on;
        #index  index.html index.htm;
    }

    location ~ /test_proxy.html$ {
        proxy_pass http://127.0.0.1:8080;   #通过代理访问8080端口
    }

After configuring the file, restart nginx -s reload

At this point we use external network through port 8080 to access, not access to.

80-port access can be a normal visit

Principle: Unable to access the server's local port 8080 as a proxy to access the service via port 80 8080

Guess you like

Origin www.cnblogs.com/joy-sir/p/12162573.html