我有一个应用程序构build在node.js 我运行在端口8000的HTTP和8003的HTTPS。 如果我在URL中给我的端口号都工作正常。
tcp6 0 0 :::8000 :::* LISTEN 4947/node tcp6 0 0 :::8003 :::* LISTEN 4947/node
我想在节点前面设置清漆,以便我可以从URL中删除端口号。
我用清漆设置的基本configuration如下。
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); }
但它不工作。 我在这里错过了什么。
您错过了解Varnish不支持SSL的情况。 您需要通过利用Nginx或Hitch来使用SSL终止。