apache 如何安装话语论坛沿着多个网站通过清漆&搭便车代理

9bfwbjaz  于 2023-05-01  发布在  Apache
关注(0)|答案(1)|浏览(130)

我用virtualmin与apache为我的其他网站。
Apache监听一端口8080清漆端口80挂接端口443对话端口8081
默认值低于**。vcl**文件,我的其他apache站点没有任何问题。虽然话语站点开放,但存在着很多问题。

  • 徽标未显示,附件不起作用。

我试图打开强制HTTPS选项在管理面板的话语,但有了这个,没有用户可以登录到网站。

我的清漆配置:

vcl 4.1;
import std;
# Default backend definition. Set this to point to your content server.
backend default {
    .host = "192.168.1.103";
    .port = "8080";
}
backend discourse {
    .host = "192.168.1.103";
    .port = "8081";
}

sub vcl_recv {
    if (req.http.host == "discourse.example.com") {
        set req.backend_hint = discourse;
        return (pipe);
    } else {
        set req.backend_hint = default;

    }

    if (std.port(server.ip) != 443) {
set req.http.location = "https://" + req.http.host + req.url;
return(synth(301));
}

    if (!req.http.X-Forwarded-Proto) {
        if(std.port(server.ip) == 443) {
            set req.http.X-Forwarded-Proto = "https";
        } else {
            set req.http.X-Forwarded-Proto = "https";
        }
    }
}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
}

sub vcl_synth {

    if (resp.status == 301 || resp.status == 302) {
        set resp.http.location = req.http.location;
        return (deliver);
    }
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
}

**我在话语应用程序中的变化。联系我们

expose: 
- "8081:80" # http
# - "443:443" # https

## Uncomment these two lines if you wish to add Lets Encrypt (https)
# - "templates/web.ssl.template.yml"
# - "templates/web.letsencrypt.ssl.template.yml"
## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
# LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

我的hitch配置更改:

pem-file = "/home/discourse/ssl.everything"

帮助我解决这个问题。

mxg2im7a

mxg2im7a1#


我的第一个猜测是你的话语结构。我不知道该软件,但如果你的错误是像HTTP 404的标志和附件,可能是一个错误的话语配置。也可以解决

  • 设置一个x-forwared-host头,类似于下面vcl_recv中的代码

http.x-forwarded-host = www.example.com ;

  • 将discours主机名硬编码到discourse配置中,如以下配置所示: www.example.com

关于VCL的一些事情。...真的很困惑

  • return(管道)调用使整个网站无法缓存。.如果你不需要缓存,为什么要使用varnish(而不是像nginx或apache httpd配置那样更容易处理的东西)
  • vcl_backend_response、vcl_synth和vcl_deliver声明是不必要的
  • 在HTTP的情况下,在重定向到https之前使用return(pipe)。.所以重定向不会为您的话语网站工作。
  • 但理论上,在您的情况下,第二个proto可能是http。.
if(std.port(server.ip) == 443) {
     set req.http.X-Forwarded-Proto = "https";
 } else {
     set req.http.X-Forwarded-Proto = "http";
 }

最后,下面的代码可能是一个足够的工作配置

vcl 4.1;
import std;
# Default backend definition. Set this to point to your content server.
backend default {
    .host = "192.168.1.103";
    .port = "8080";
}
# Discours backend declaration
backend discourse {
    .host = "192.168.1.103";
    .port = "8081";
}

sub vcl_recv {

    if (std.port(server.ip) != 443) {
         set req.http.location = "https://" + req.http.host + req.url;
         return(synth(301));
    }

    if (!req.http.X-Forwarded-Proto) {
        if(std.port(server.ip) == 443) {
            set req.http.X-Forwarded-Proto = "https";
        } else {
            set req.http.X-Forwarded-Proto = "http";
        }
    }
    if (req.http.host == "discourse.example.com") {
        # Telling discourse the website is discourse.example.com
        # might be sufficient (if not, hardcode your website hostname into discourse
        set req.http.x-forwarded-host = req.http.host;
        set req.backend_hint = discourse;
        # Do you really want a pipe
        # (i.e. pathing the request to discourse without any transformation/cache? )
        return (pipe);
    } else {
        set req.backend_hint = default;
    }
}

相关问题