nginx 部署后端项目(Nginx deployment backend project)

nginx 部署后端实际上进行了一个代理模式。

    服务器对外开放端口为80;  你的项目运行在 5555 端口; 当你的浏览器访问, 服务器80 端口, 服务器会将数据转发到 5555 端口。 

# 客户端接口
server{
    listen 80;
    server_name 123.56.223.123;
    location /{
            proxy_pass http://127.0.0.1:5555;
            proxy_redirect off;
            proxy_set_header   Host                 $http_host;
            proxy_set_header   X-Real-IP            $remote_addr;
            proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto    $scheme;
    }
 
 
}
# 后台接口
server{
    listen 8000;
    server_name 123.56.223.123;
    location /{
            proxy_pass http://127.0.0.1:5558;
            proxy_redirect off;
            proxy_set_header   Host                 $http_host;
            proxy_set_header   X-Real-IP            $remote_addr;
            proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto    $scheme;
    }
 
}  

设置完后重启nginx 

nginx -s reload
————————

The nginx deployment backend actually implements a proxy pattern.

The open port of the server is 80; Your project runs on port 5555; When your browser accesses port 80, the server will forward the data to port 5555.

# 客户端接口
server{
    listen 80;
    server_name 123.56.223.123;
    location /{
            proxy_pass http://127.0.0.1:5555;
            proxy_redirect off;
            proxy_set_header   Host                 $http_host;
            proxy_set_header   X-Real-IP            $remote_addr;
            proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto    $scheme;
    }
 
 
}
# 后台接口
server{
    listen 8000;
    server_name 123.56.223.123;
    location /{
            proxy_pass http://127.0.0.1:5558;
            proxy_redirect off;
            proxy_set_header   Host                 $http_host;
            proxy_set_header   X-Real-IP            $remote_addr;
            proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto    $scheme;
    }
 
}  

Restart nginx after setting

nginx -s reload