ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

简单配置Nginx和Varnish

2019-11-22 12:10:17  阅读:369  来源: 互联网

标签:remote-server varnish nginx


我在同一网络(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等).

标签:remote-server,varnish,nginx
来源: https://codeday.me/bug/20191122/2059792.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有