使用Nginx作为一个普通代理服务器

使用Nginx作为一个普通代理服务器, 请不要用于违法用途哦

nginx作为一个反向代理工具,除了可以进行反向代理之外,还可以用来作为代理工具来使用,作为代理工具使用的步骤如下,这个配置目前支持对访问http协议的网站进行代理,暂不支持https

  1. Windows系统代理设置对应IP, 端口8011

  2. 日志配置:

http {
    
    
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # access_log  logs/access.log  main;
log_format json '{"remote_addr":"$remote_addr","remote_user":"$remote_user",'
                       '"request":"$request","status":"$status","remote_user":"$bytes_sent",'
                       '"http_referer":"$http_referer","http_user_agent":"$http_user_agent","$server_name","$hostname", "$host","$http_host", "$request_uri", "$request_method"}';

access_log D:/data/logs/nginx/nginx-access.log json buffer=1k;



}
对应请求日志: 
{"remote_addr":"192.168.11.11","remote_user":"-","request":"GET http://192.168.2.2:17000/?t=123 HTTP/1.1","status":"200","remote_user":"97103","http_referer":"-","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36","192.168.11.11","c-xxx", "192.168.2.2","192.168.2.2:17000", "/?t=123", "GET"}
  1. 代理配置:
server {
    
    
    listen       8011;
    server_name  192.168.11.11 localhost;

    #charset koi8-r;

    # access_log  D:/develop/nginx/nginx-v1.21.5-2/nginx-1.21.5/logs/host.access.log  main;


    location / {
    
    
        proxy_set_header Host $http_host;
        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_pass http://$http_host$request_uri;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_27577113/article/details/131282631