我有3臺計算機在同一網絡(LAN)。我想將一臺計算機配置爲Nginx Web-Server,另一臺計算機配置爲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和Varnish
你能給我的基本配置適合我的環境?
如果你想看看我的 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 /默認/清漆:
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
感謝提前:)
你可以在後端使用nginx upstream - 這是清漆。確保IP地址和端口匹配 –
proxy_pass應該工作提供清漆指向該IP地址/端口 –
設置所有端口= 81(DAEMON_OPTS除外),我得到502在本地主機壞網關:81 – TheSoulkiller