Home > Article > Backend Development > What is Nginx proxy service? Examples of nginx forward proxy and reverse proxy
This article introduces to you what is Nginx proxy service? The examples of nginx forward proxy and reverse proxy have certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
##2. Nginx proxy service
3. The difference between forward proxy and reverse proxy is that the objects of the proxy are different.
4. Nginx proxy module ngx_http_proxy_module
Syntax: proxy_pass URL; Default: — Context: location, if in location, limit_except
http: //localhost:8000/uri/
https://192.168.1.111:8000/uri/
http://unix:/tmp/backend.socket:/uri/
server { # 监听8080端口 listen 8080; location / { # 配置访问根目录为 /vagrant/proxy root /vagrant/proxy; } }
server { # 监听80端口 listen 80; server_name localhost; location ~ /fx_proxy.html { # 设置反向代理,将访问 /fx_proxy.html 的请求转发到 http://127.0.0.1:8080 proxy_pass http://127.0.0.1:8080; } }
file
nbsp;html> <meta> <title>反向代理</title> <h1>反向代理</h1>
to check whether port 80 and port 8080 are all open
[root~]# ss -tln State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:8080 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 10 127.0.0.1:25 *:* LISTEN 0 128 :::22 :::*
http://127.0.0.1/fx_proxy.htmlcan be accessed normally
[root~]# curl http://127.0.0.1/fx_proxy.html nbsp;html> <meta> <title>反向代理</title> <h1>反向代理</h1>
http://127.0.0.1:8080/fx_proxy.htmlcan be accessed normally
[root~]# curl http://127.0.0.1:8080/fx_proxy.html nbsp;html> <meta> <title>反向代理</title> <h1>反向代理</h1>3. Forward proxy instance
The IP address of the author's remote server is: 39.106.178.166, and the domain name used for testing is zx_proxy.ws65535.top
vim conf.d/real_server.conf
server { # 监听80端口 listen 80; # 域名为 zx_proxy.ws65535.top; server_name zx_proxy.ws65535.top; location / { # $http_x_forwarded_for 可以记录客户端及所有中间代理的IP # 判断客户端IP地址是否是 39.106.178.166,不是则返回403 if ($http_x_forwarded_for !~* "^39\.106\.178\.166") { return 403; } root /usr/share/nginx/html; index index.html; } }
http://zx_proxy.ws65535.top/
,返回 403 Forbidden
,说明访问被拒绝
vim conf.d/zx_proxy.conf
server { # 代理服务监听的端口(注意,一定要看服务器供应商控制台的安全组是否开启了该端口) listen 3389; # 配置DNS,223.5.5.5是阿里云的DNS resolver 223.5.5.5; # 正向代理配置 location / { proxy_pass http://$http_host$request_uri; } }
控制面板 -> 网络和Internet -> 代理 -> 手动设置代理
http://zx_proxy.ws65535.top/
,可以正常访问相关文章推荐:
The above is the detailed content of What is Nginx proxy service? Examples of nginx forward proxy and reverse proxy. For more information, please follow other related articles on the PHP Chinese website!