Pages

Friday, 1 November 2024

如何使Apache做反向代理



需要启用apache的反代模块 mod_proxy.c

<VirtualHost *:80>
    ServerName your_domain.com
    ServerAlias

    RewriteEngine On
    RewriteCond %{QUERY_STRING} transport=polling         [NC]
    RewriteRule /(.*)           http://localhost:23366/$1 [P]

    <IfModule mod_proxy.c>
        ProxyRequests Off
        SSLProxyEngine on
        ProxyPass / http://localhost:23366/
        ProxyPassReverse / http://localhost:23366/

    </IfModule>
</VirtualHost>

--------------------------------------------------------

如何用caddy做反向代理

nano /etc/caddy/Caddyfile

yourdomain.com {
  tls /etc/caddy/ssl/cert.pem /etc/caddy/ssl/cert.key

  reverse_proxy http://localhost:23366 {
    header_up X-Forwarded-For {header.X-Forwarded-For}
  }
}

执行重载命令:
systemctl reload caddy 

--------------------------

如何使nginx做反向代理

编辑nginx的配置文件:

server
{
  listen 80;
  listen [::]:80;

  server_name your_domain.com;

  location / {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:23366/;
  }
}

如果你正在使用 CDN 或者 Nginx 等可信的反向代理服务器,那么你需要在「设置」-「服务器」选项 -「代理标头名 (http.proxy_header)」填写包含用户真实 IP 的请求头字段名,如:X-Real-IP

No comments:

Post a Comment