Loading

使用正向 HTTPS 代理代替 /etc/hosts

1. 运行 NGINX 作为正向 HTTPS 代理

  • 创建文件 nginx.conf
daemon off;
worker_processes auto;
worker_rlimit_nofile 65535;

events {
  multi_accept on;
  worker_connections 65535;
}

http {
  charset utf-8;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  server_tokens off;
  log_not_found off;
  types_hash_max_size 2048;
  types_hash_bucket_size 64;
  client_max_body_size 16M;

  # MIME
  include mime.types;
  default_type application/octet-stream;

  # Logging
  access_log /dev/stdout;
  error_log /dev/stdout warn;

  # DNS
  resolver 223.5.5.5 223.6.6.6;
  resolver_timeout 2s;

  # Proxy
  proxy_connect_timeout 10s;
  proxy_send_timeout 10s;
  proxy_read_timeout 10s;
  proxy_buffer_size 4k;
  proxy_buffers 4 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;

  server {
    listen 8888;
    server_name <TODO-DOMAIN>;

    # forward proxy for CONNECT request
    proxy_connect;
    proxy_connect_address <TODO-IP>;
    proxy_connect_connect_timeout 10s;
    proxy_connect_read_timeout 10s;
    proxy_connect_send_timeout 10s;

    # forward proxy for non-CONNECT request
    location / {
      return 500;
    }
  }

  server {
    listen 8888;
    server_name ~.+;

    location / {
      return 404;
    }
  }
}

注意:需要将 <TODO-DOMAIN><TODO-IP> 替换为原 /etc/hosts 文件中对应的域名和IP地址,可以(按需复制)包含多个 server 配置块。

  • 创建 docker-compose.yaml
version: "3"
services:
  nginx_proxy:
    image: reiz/nginx_proxy
    volumes:
    - ./nginx.conf:/usr/local/nginx/conf/nginx.conf:ro
    ports:
    - 8888:8888
    restart: unless-stopped

注意:这里暴露服务到本地端口 8888

  • 后台运行 NGINX(正向 HTTPS 代理)
 docker-compose up -d

2. Chrome/Edge 浏览器配置 Proxy SwitchyOmega 插件

posted @ 2021-07-02 12:13  roy2220  阅读(949)  评论(0编辑  收藏  举报