简单配置Nginx和Varnish

我在同一网络(LAN)上有3台计算机.我想将一台计算机配置为Nginx Web服务器,将另一台计算机配置为Varnish Cache服务器和一个客户端.我成功安装了一个(比如说A)Nginx(192.168.0.15)和B Varnish(192.168.0.20).我将A配置为网络服务器,并且可以从其他计算机浏览index.html.但我无法将其与B连接.
我搞砸了“ nginx.conf”和“ /sites-available/server.com”以及Varnish的“ default.vcl”

您能给我一些适合我环境的基本配置吗?

如果你想看看
我的nginx.conf:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    #gzip  on;
    include /etc/nginx/conf.d/*.conf;

    upstream dynamic_node {
            server 1.1.1.1:80; # 1.1.1.1 is the IP of the Dynamic Node
        }
    server {
        listen      81;
        server_name  myserver.myhome.com;
        location / {
        #root /var/www/server.com/public_html;
        #index index.html index.htm;

        # pass the request on to Varnish
        proxy_pass http://192.168.0.20;

        # Pass a bunch of headers to the downstream server.
        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_redirect     off; 
        }
    }
}

/sites-available/server.com:

服务器{

listen   80;
server_name myserver.myhome.com;

access_log /var/www/server.com/access.log;
error_log /var/www/server.com/error.log;

}

和default.vcl这样的:

backend web1 {
    .host = "192.168.0.15";
    .port = "8080";
}
sub vcl_recv {
    if (req.http.host == "192.168.0.15") {

        #set req.http.host = "myserver.myhome.com";
        set req.backend = web1;
    }   
}

最后/ etc / default / varnish:

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

提前致谢 :)

最佳答案
现在,您的清漆实例正在侦听端口6081.这需要在proxy_pass中为nginx指定,例如

proxy_pass http://192.168.0.20:6081 

我假设您提到的IP地址正确,并且计算机之间的网络连接不受限制.

更新资料

请记住,您可以在清漆前使用nginx或反之. nginx和varnish都可以充当后端服务的代理.
您当前的实现使用nginx作为代理.这意味着您可以依赖proxy_pass或在nginx中使用上游模块(以防您希望通过多个清漆实例在后面进行负载平衡,而前面仅使用一个nginx).本质上,无论是哪个代理,代理中指定的后端的IP地址和端口号(在您的情况下为nginx)必须与后端服务的IP地址和端口号(在您的情况下为清漆)匹配. varnish的后端需要匹配您正在使用的任何应用程序服务器/服务的IP地址和端口号(tomcat / netty / django / ror等).

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...