【问题标题】:How to set up varnish 4.1.2 with multiple apache virtual hosts?如何使用多个 apache 虚拟主机设置 varnish 4.1.2?
【发布时间】:2016-08-31 19:50:39
【问题描述】:

我正在尝试设置 Varnish 和 Apache 以通过一个 VPS 为多个网站提供服务。但是,当我在浏览器中输入 seconddomain.nl 时,我被重定向到默认的 apache2 起始页(带有一个作为 VPS IP 地址的 url)。但是,firstdomain.nl 工作得很好。我的设置是这样的:

etc/default/varnish:

DAEMON_OPTS="-a :80 \
             -T localhost:1234 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

(部分省略)

/etc/varnish/default.vcl:

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

/etc/apache2/ports.conf:

NameVirtualHost *:8080
Listen 127.0.0.1:8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:8080>
        ServerName 188.166.71.35

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

         <Directory /var/www/jws/>
            AllowOverride All
         </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/sites-available/seconddomain.nl.conf:

<VirtualHost *:8080>

        ServerAdmin janwillem@seconddomain.nl
        ServerName seconddomain.nl
        ServerAlias www.seconddomain.nl
        DocumentRoot /var/www/jws

        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fjanwillem@seconddomain.nl
        ErrorLog ${APACHE_LOG_DIR}/error-seconddomain.log
        CustomLog ${APACHE_LOG_DIR}/access-seconddomain.log combined
</VirtualHost>

/etc/apache2/sites-available/firstdomain.nl.conf:

<VirtualHost *:8080>

        ServerAdmin info@firstdomain.nl
        ServerName firstdomain.nl
        ServerAlias www.firstdomain.nl
        DocumentRoot /var/www/firstdomain.nl

        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -finfo@cool-hou$
        ErrorLog ${APACHE_LOG_DIR}/error-firstdomain.log
        CustomLog ${APACHE_LOG_DIR}/access-firstdomain.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =firstdomain.nl [OR]
RewriteCond %{SERVER_NAME} =www.firstdomain.nl
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

【问题讨论】:

  • 没有 Varnish 也能工作吗? (如果您同时使用两个域名冲浪到 :8080?)
  • @Jensd 使用 curl 在我的本地计算机上的浏览器中我得到:无法连接到 seconddomain.nl 端口 8080:操作超时。第一个域也是如此。在 VPS 中,我收到连接被拒绝(对于两者)。
  • 那么您的问题出在 Apache 或服务器本身 - 而不是 Varnish!有防火墙在运行吗?
  • @Jensd 所以使用netstat -ln | grep 8080 我得到tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN,这表明apache 正在本地侦听端口8080。 (它和 varnish 在同一个 VPS 上。)
  • 尝试设置实际 IP 而不是 127.0.0.1 或 localhost

标签: apache virtualhost varnish varnish-4


【解决方案1】:

我的配置和你的一样,解决方法是删除/etc/apache2/ports.conf中的127.0.0.1

这就是我现在的方式并且它可以工作(我评论了更改的行):

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

#Listen 127.0.0.1:8080
Listen 8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

【讨论】:

    猜你喜欢
    • 2013-03-03
    • 2017-05-30
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 2021-12-29
    • 2012-04-22
    • 1970-01-01
    相关资源
    最近更新 更多