У меня есть встроенное приложение node.js
. Я запускаю его на порту 8000
для http и 8003
для https. Если я укажу свой номер порта в URL-адресе, оба будут работать нормально.
tcp6 0 0 :::8000 :::* LISTEN 4947/node
tcp6 0 0 :::8003 :::* LISTEN 4947/node
Я хотел нанести лак перед узлом, чтобы можно было удалить номер порта из URL.
Базовая конфигурация, которую я создал с помощью лака, приведена ниже.
backend newstack {
.host = "127.0.0.1";
.port = "8000";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
}
backend sslnewstack {
.host = "127.0.0.1";
.port = "8003";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
}
/*
*
* Next, configure the "receive" subroutine.
*
*/
sub vcl_recv {
# Use the backend we set up above to answer the request if it's not cached.
if(req.http.host ~ "dev.domain.com" && req.http.X-Forwarded-Proto ~ "(?i)http"){
set req.backend = newstack;
return(pipe);
}
if(req.http.host ~ "dev.domain.com" && req.http.X-Forwarded-Proto ~ "(?i)https"){
set req.backend = sslnewstack;
return(pass);
}
}
sub vcl_miss {
return(fetch);
}
/*
*
* Now, let's set up a subroutine to deal with cache hits.
*
*/
sub vcl_hit {
return(deliver);
}
/*
*
* This is the subroutine which will fetch a response from the backend.
* It's pretty fancy because this is where the basic logic for caching is set.
*
*/
sub vcl_fetch {
# Get the response. Set the cache lifetime of the response to 1 hour.
set beresp.ttl = 1h;
# Indicate that this response is cacheable. This is important.
set beresp.http.X-Cacheable = "NO";
# Some backends *cough* Django *cough* will assign a Vary header for
# each User-Agent which visits the site. Varnish will store a separate
# copy of the page in the cache for each instance of the Vary header --
# one for each User-Agent which visits the site. This is bad. So we're
# going to strip away the Vary header.
unset beresp.http.Vary;
# Now pass this backend response along to the cache to be stored and served.
return(deliver);
}
/*
*
* Finally, let's set up a subroutine which will deliver a response to the client.
*
*/
sub vcl_deliver {
return(deliver);
}
Но это не работает. Что мне здесь не хватает.
Вам не хватает понимания, что SSL не поддерживается в Varnish. Вам необходимо использовать завершение SSL, используя Nginx или Hitch.