简单配置Nginx和清漆

简单配置Nginx和清漆,nginx,varnish,remote-server,Nginx,Varnish,Remote Server,我在同一网络(LAN)上有3台计算机。我想将一台计算机配置为nginxweb服务器,另一台配置为Varnish缓存服务器和一个客户端。我成功地安装了一个(比方说A)Nginx(192.168.0.15)和B Varnish(192.168.0.20)。我将配置为Web服务器,可以从其他计算机浏览index.html。但我不能把它和B联系起来。 我搞砸了“nginx.conf”和“/sites available/server.com”以及Varnish的“default.vcl” 你能给我一些适

我在同一网络(LAN)上有3台计算机。我想将一台计算机配置为nginxweb服务器,另一台配置为Varnish缓存服务器和一个客户端。我成功地安装了一个(比方说A)Nginx(192.168.0.15)和B Varnish(192.168.0.20)。我将配置为Web服务器,可以从其他计算机浏览index.html。但我不能把它和B联系起来。 我搞砸了“nginx.conf”和“/sites available/server.com”以及Varnish的“default.vcl”

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

如果你想看看 My 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; 
        }
    }
}
/可用站点/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"

提前感谢:)

现在,您的varnish实例正在监听端口6081。这需要在nginx的代理_过程中指定,例如

proxy_pass http://192.168.0.20:6081 
我假设您提到的ip地址是正确的,并且计算机之间的网络连接不受限制

更新

请记住,您可以在清漆前使用nginx,也可以使用其他方式。nginx和varnish都可以作为后端服务的代理。

您当前的实现使用nginx作为代理。这意味着您可以依赖proxy_pass或使用nginx中的上游模块(如果您希望在前面只有一个nginx的多个varnish实例的情况下实现负载平衡)。本质上,无论代理是哪一个,代理中指定的后端ip地址和端口号(在您的情况下为nginx)必须与后端服务(在您的情况下为varnish)的ip地址和端口号匹配。varnish中的后端需要与您正在使用的应用程序服务器/服务(tomcat/netty/django/ror等)的ip地址和端口号相匹配。

您可以使用nginx上游作为后端-这就是varnish。如果varnish指向ip地址/portSet all ports=81(守护进程选项除外),请确保ip地址和端口匹配Proxy_pass也能正常工作我在本地主机上得到了502个坏网关:81在nginx的proxy_pass中指定端口号-这需要是varnish正在侦听连接的端口我更改了proxy_pass(尝试6081)并尝试通过curl获得varnish头-I 192.168.0.15,但我无法获得。我是服务器配置新手,所以你能告诉我正确的方法吗?但是后端web1{.host=“192.168.0.15”;.port=“8080”}配置是真的吗?我正在更新答案以回答你的问题,现在我非常理解。最后一个问题:对于后端服务器(您说的tomcat/netty),如果我将varnish配置为后端web1{.host=“192.168.0.25”;.port=“8080”}假设192.168.0.25是实际的web服务器,那么该web服务器的配置是什么?我是否应该将侦听端口指定为8080?如果在varnish中指定后端web1{.host=“192.168.0.25”;.port=“8080”},则后端web服务器应该在该ip地址和端口上运行,即192.168.0.25和8080。希望能有帮助