使用 lighttpd 通过代理访问网站

使用 lighttpd 通过代理访问网站

这是我的第一个问题。

我们公司使用 Squid 作为内联网和互联网之间的代理。现在我们需要一个软件包,它不能处理代理服务器 - 它需要直接互联网访问。

所以我的想法是使用 lighttpd 作为此应用程序与互联网之间的“桥梁”。这样应用程序就可以调用“mylighttpd:91234”并查看 Google 页面,而浏览器中的地址仍然是“mylighttpd:91234”。

我的 lighttpd.conf 如下所示:

config {
var.PID                        = 13793
var.CWD                        = "/home/testusr"
var.log_root                   = "/tmp/lighttpd-log"
var.server_root                = "/tmp/lighttpd-data"
var.state_dir                  = "/tmp/lighttpd-var/run"
var.home_dir                   = "/var/lib/lighttpd"
var.conf_dir                   = "/etc/lighttpd"
var.vhosts_dir                 = "/tmp/lighttpd-data/vhosts"
var.cache_dir                  = "/var/cache/lighttpd"
var.socket_dir                 = "/var/lib/lighttpd/sockets"
server.modules                 = (
    "mod_indexfile",
    "mod_access",
    "mod_proxy",
    "mod_status",
    "mod_accesslog",
    "mod_redirect",
    "mod_rewrite",
    "mod_accesslog",
    "mod_dirlisting",
    "mod_staticfile",
    # 10
)
server.port                    = 91234
server.use-ipv6                = "disable"
server.username                = "testusr"
server.groupname               = "testgroup"
server.document-root           = "/tmp/lighttpd-data/htdocs"
server.pid-file                = "/tmp/lighttpd-var/run/lighttpd.pid"
server.errorlog                = "/tmp/lighttpd-log/error.log"
accesslog.filename             = "/tmp/lighttpd-log/access.log"
server.event-handler           = "linux-sysepoll"
server.network-backend         = "linux-sendfile"
server.max-fds                 = 2048
server.stat-cache-engine       = "simple"
server.max-connections         = 1024
index-file.names               = ("index.xhtml", "index.html", "index.htm", "default.htm", "index.php")
url.access-deny                = ("~", ".inc")
url.redirect                   = (
    "^/(.*)" => "http://google.com/$1",
)
proxy.debug                    = 1
proxy.server                   = (
    "" => (
        (
            "host" => "192.168.1.10",
            "port" => 8080,
            # 2
        ),
    ),
)
static-file.exclude-extensions = (".php", ".pl", ".fcgi", ".scgi")
mimetype.use-xattr             = "disable"
mimetype.assign                = (
    ".pdf"     => "application/pdf",
    ".sig"     => "application/pgp-signature",
    ".spl"     => "application/futuresplash",
    ".class"   => "application/octet-stream",
    ".ps"      => "application/postscript",
    # 5
    ".torrent" => "application/x-bittorrent",
    ".dvi"     => "application/x-dvi",
    ".gz"      => "application/x-gzip",
    ".pac"     => "application/x-ns-proxy-autoconfig",
    ".swf"     => "application/x-shockwave-flash",
    # 10
    ".tar.gz"  => "application/x-tgz",
    ".tgz"     => "application/x-tgz",
    ".tar"     => "application/x-tar",
    ".zip"     => "application/zip",
    ".mp3"     => "audio/mpeg",
    # 15
    ".m3u"     => "audio/x-mpegurl",
    ".wma"     => "audio/x-ms-wma",
    ".wax"     => "audio/x-ms-wax",
    ".ogg"     => "application/ogg",
    ".wav"     => "audio/x-wav",
    # 20
    ".gif"     => "image/gif",
    ".jpg"     => "image/jpeg",
    ".jpeg"    => "image/jpeg",
    ".png"     => "image/png",
    ".xbm"     => "image/x-xbitmap",
    # 25
    ".xpm"     => "image/x-xpixmap",
    ".xwd"     => "image/x-xwindowdump",
    ".css"     => "text/css",
    ".html"    => "text/html",
    ".htm"     => "text/html",
    # 30
    ".js"      => "text/javascript",
    ".asc"     => "text/plain",
    ".c"       => "text/plain",
    ".cpp"     => "text/plain",
    ".log"     => "text/plain",
    # 35
    ".conf"    => "text/plain",
    ".text"    => "text/plain",
    ".txt"     => "text/plain",
    ".spec"    => "text/plain",
    ".dtd"     => "text/xml",
    # 40
    ".xml"     => "text/xml",
    ".mpeg"    => "video/mpeg",
    ".mpg"     => "video/mpeg",
    ".mov"     => "video/quicktime",
    ".qt"      => "video/quicktime",
    # 45
    ".avi"     => "video/x-msvideo",
    ".asf"     => "video/x-ms-asf",
    ".asx"     => "video/x-ms-asf",
    ".wmv"     => "video/x-ms-wmv",
    ".bz2"     => "application/x-bzip",
    # 50
    ".tbz"     => "application/x-bzip-compressed-tar",
    ".tar.bz2" => "application/x-bzip-compressed-tar",
    ".rpm"     => "application/x-rpm",
    ""         => "application/octet-stream",
    # 54
)
dir-listing.activate           = "disable"
dir-listing.hide-dotfiles      = "disable"
dir-listing.exclude            = ("~$")
dir-listing.encoding           = "UTF-8"
dir-listing.hide-header-file   = "disable"
dir-listing.show-header        = "disable"
dir-listing.hide-readme-file   = "disable"
dir-listing.show-readme        = "disable"
server.follow-symlink          = "enable"
server.upload-dirs             = ("/var/tmp")


$HTTP["url"] =~ "\.pdf$" {
    # block 1
    server.range-requests = "disable"

} # end of $HTTP["url"] =~ "\.pdf$"
}

其中: * 91234:lighttpd 监听的端口 * 192.168.1.10:Squid 代理的 IP * www.google.de:lighttpd 应通过代理转发到的页面。

目前,当我在浏览器中输入“localhost:9123”时,它会打开 Google 页面,但它会将地址替换为 www.google.com,而该地址应该保留在“localhost:9123”。

我已阅读了 lighttpd 和 Apache 有关转发、重定向和代理的文档,但我无法用不同的方式来表达——它根本就无法进入我的脑海。

感谢您的帮助和理解。

答案1

只是设置拦截,将所有出站请求从该服务器重定向到 squid。这并非易事,您甚至可能需要为其设置第二个 squid 服务器,但它比上述建议要简洁得多,甚至使用您已经熟悉的工具。

答案2

我现在用 Apache 解决了这个问题。这是配置文件的片段,它起到了作用:

<VirtualHost *:80>
    ...

    ProxyRemote * http://proxy.example.com:8080

    ProxyPass / http://google.com/
    ProxyPassReverse / http://google.com/

    RewriteEngine on
    RewriteRule ^(.*)$ http://www.google.com/$1 [P]
</VirtualHost>

相关内容