1"use strict";(self.webpackChunkcloudpanel_ce_docusaurus_clp=self.webpackChunkcloudpanel_ce_docusaurus_clp||[]).push([[6006],{3905:(e,t,r)=>{r.d(t,{kt:()=>h});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function i(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),l=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},c="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},d=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),d=l(r),h=a,m=d["".concat(p,".").concat(h)]||d[h]||u[h]||o;return r?n.createElement(m,s(s({ref:t},c),{},{components:r})):n.createElement(m,s({ref:t},c))}));function h(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,s=new Array(o);s[0]=d;var i={};for(var p in t)hasOwnProperty.call(t,p)&&(i[p]=t[p]);i.originalType=e,i[c]="string"==typeof e?e:a,s[1]=i;for(var l=2;l<o;l++)s[l]=r[l];return n.createElement.apply(null,s)}return n.createElement.apply(null,r)}d.displayName="MDXCreateElement"},3919:(e,t,r)=>{function n(e){return!0===/^(\w*:|\/\/)/.test(e)}function a(e){return void 0!==e&&!n(e)}r.d(t,{Z:()=>a,b:()=>n})},4996:(e,t,r)=>{r.d(t,{C:()=>o,Z:()=>s});var n=r(2263),a=r(3919);function o(){const{siteConfig:{baseUrl:e="/",url:t}={}}=(0,n.Z)();return{withBaseUrl:(r,n)=>function(e,t,r,n){let{forcePrependBaseUrl:o=!1,absolute:s=!1}=void 0===n?{}:n;if(!r)return r;if(r.startsWith("#"))return r;if((0,a.b)(r))return r;if(o)return t+r;const i=r.startsWith(t)?r:t+r.replace(/^\//,"");return s?e+i:i}(t,e,r,n)}}function s(e,t){void 0===t&&(t={});const{withBaseUrl:r}=o();return r(e,t)}},8215:(e,t,r)=>{r.d(t,{Z:()=>a});var n=r(7294);const a=function(e){let{children:t,hidden:r,className:a}=e;return n.createElement("div",{role:"tabpanel",hidden:r,className:a},t)}},5064:(e,t,r)=>{r.d(t,{Z:()=>u});var n=r(7294),a=r(9443);const o=function(){const e=(0,n.useContext)(a.Z);if(null==e)throw new Error('"useUserPreferencesContext" is used outside of "Layout" component.');return e};var s=r(6010);const i="tabItem_vU9c",p="tabItemActive_cw6a";const l=37,c=39;const u=function(e){const{lazy:t,block:r,defaultValue:a,values:u,groupId:d,className:h}=e,{tabGroupChoices:m,setTabGroupChoices:g}=o(),[f,k]=(0,n.useState)(a),v=n.Children.toArray(e.children),b=[];if(null!=d){const e=m[d];null!=e&&e!==f&&u.some((t=>t.value===e))&&k(e)}const N=e=>{const t=e.currentTarget,r=b.indexOf(t),n=u[r].value;k(n),null!=d&&(g(d,n),setTimeout((()=>{(function(e){const{top:t,left:r,bottom:n,right:a}=e.getBoundingClientRect(),{innerHeight:o,innerWidth:s}=window;return t>=0&&a<=s&&n<=o&&r>=0})(t)||(t.scrollIntoView({block:"center",behavior:"smooth"}),t.classList.add(p),setTimeout((()=>t.classList.remove(p)),2e3))}),150))},y=e=>{var t;let r;switch(e.keyCode){case c:{const t=b.indexOf(e.target)+1;r=b[t]||b[0];break}case l:{const t=b.indexOf(e.target)-1;r=b[t]||b[b.length-1];break}}null==(t=r)||t.focus()};return n.createElement("div",{className:"tabs-container"},n.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":r},h)},u.map((e=>{let{value:t,label:r}=e;return n.createElement("li",{role:"tab",tabIndex:f===t?0:-1,"aria-selected":f===t,className:(0,s.Z)("tabs__item",i,{"tabs__item--active":f===t}),key:t,ref:e=>b.push(e),onKeyDown:y,onFocus:N,onClick:N},r)}))),t?(0,n.cloneElement)(v.filter((e=>e.props.value===f))[0],{className:"margin-vert--md"}):n.createElement("div",{className:"margin-vert--md"},v.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==f})))))}},9443:(e,t,r)=>{r.d(t,{Z:()=>n});const n=(0,r(7294).createContext)(void 0)},8895:(e,t,r)=>{r.r(t),r.d(t,{contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>i,toc:()=>p});var n=r(7462),a=(r(7294),r(3905));r(4996),r(5064),r(8215);const o={id:"vhost",title:"Developer Guide - Vhost",sidebar_label:"Vhost"},s=void 0,i={unversionedId:"frontend-area/varnish-cache/developer-guide/vhost",id:"frontend-area/varnish-cache/developer-guide/vhost",isDocsHomePage:!1,title:"Developer Guide - Vhost",description:"Basics",source:"@site/docs/frontend-area/varnish-cache/developer-guide/vhost.md",sourceDirName:"frontend-area/varnish-cache/developer-guide",slug:"/frontend-area/varnish-cache/developer-guide/vhost",permalink:"/docs/v2/frontend-area/varnish-cache/developer-guide/vhost",editUrl:"https://github.com/cloudpanel-io/docs/tree/master/cloudpanel-ce/docs/frontend-area/varnish-cache/developer-guide/vhost.md",version:"current",frontMatter:{id:"vhost",title:"Developer Guide - Vhost",sidebar_label:"Vhost"},sidebar:"sidebar",previous:{title:"Settings",permalink:"/docs/v2/frontend-area/varnish-cache/settings"},next:{title:"PHP Controller",permalink:"/docs/v2/frontend-area/varnish-cache/developer-guide/php-controller"}},p=[{value:"Basics",id:"basics",children:[]},{value:"Vhost Explanation",id:"vhost-explanation",children:[]}],l={toc:p},c="wrapper";
1function u(e){let{components:t,...r}=e;return(0,a.kt)(c,(0,n.Z)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h2",{id:"basics"},"Basics"),(0,a.kt)("p",null,(0,a.kt)("a",{parentName:"p",href:"http://varnish-cache.org/"},"Varnish Cache")," is a caching HTTP reverse proxy that speeds up your sites by storing the compressed ",(0,a.kt)("strong",{parentName:"p"},"Page Source")," in memory. ",(0,a.kt)("br",null),"\nStatic files like ",(0,a.kt)("strong",{parentName:"p"},"CSS, JS,")," and ",(0,a.kt)("strong",{parentName:"p"},"Images")," are ",(0,a.kt)("strong",{parentName:"p"},"NOT")," being stored in ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," because ",(0,a.kt)("strong",{parentName:"p"},"NGINX")," delivers them faster."),(0,a.kt)("p",null,"When you open your site, e.g., ",(0,a.kt)("strong",{parentName:"p"},(0,a.kt)("a",{parentName:"strong",href:"https://www.domain.com"},"https://www.domain.com")),", the request goes to ",(0,a.kt)("strong",{parentName:"p"},"NGINX"),", where ",(0,a.kt)("strong",{parentName:"p"},"SSL/TLS")," gets terminated. ",(0,a.kt)("br",null),"\nIf the request is a static file like a ",(0,a.kt)("strong",{parentName:"p"},"Stylesheet"),", ",(0,a.kt)("strong",{parentName:"p"},"Javascript"),", or an ",(0,a.kt)("strong",{parentName:"p"},"Image"),", it gets delivered immediately by ",(0,a.kt)("strong",{parentName:"p"},"NGINX"),". ",(0,a.kt)("br",null),"\nAll other requests are forwarded to ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," (Port ",(0,a.kt)("strong",{parentName:"p"},"6081"),")."),(0,a.kt)("p",null,"If ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," has a cache entry for a request, the page source gets immediately returned from memory without being processed by ",(0,a.kt)("strong",{parentName:"p"},"PHP-FPM"),"."),(0,a.kt)("p",null,"If no cache entry exists, the request gets forwarded\nby ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," to ",(0,a.kt)("strong",{parentName:"p"},"NGINX")," port ",(0,a.kt)("strong",{parentName:"p"},"8080"),", where it gets processed by the ",(0,a.kt)("strong",{parentName:"p"},"PHP Application")," via ",(0,a.kt)("strong",{parentName:"p"},"PHP-FPM"),"."),(0,a.kt)("h2",{id:"vhost-explanation"},"Vhost Explanation"),(0,a.kt)("p",null,"The ",(0,a.kt)("strong",{parentName:"p"},"Vhost")," below is being used for ",(0,a.kt)("strong",{parentName:"p"},"WordPress/WooCommerce"),"."),(0,a.kt)("p",null,"In line ",(0,a.kt)("strong",{parentName:"p"},"1-14")," a redirect for ",(0,a.kt)("strong",{parentName:"p"},"domain.com")," takes place. All requests from ",(0,a.kt)("strong",{parentName:"p"},"http")," and ",(0,a.kt)("strong",{parentName:"p"},"https")," are redirected via ",(0,a.kt)("strong",{parentName:"p"},"301")," to ",(0,a.kt)("strong",{parentName:"p"},(0,a.kt)("a",{parentName:"strong",href:"https://www.domain.com"},"https://www.domain.com")),". "),(0,a.kt)("p",null,"The static files like ",(0,a.kt)("strong",{parentName:"p"},"CSS, JS"),", and ",(0,a.kt)("strong",{parentName:"p"},"Images")," are delivered at line ",(0,a.kt)("strong",{parentName:"p"},"84-92"),". ",(0,a.kt)("br",null),"\nAll other requests are going through the ",(0,a.kt)("strong",{parentName:"p"},"location /"),", line ",(0,a.kt)("strong",{parentName:"p"},"66-82"),"."),(0,a.kt)("p",null,"At line ",(0,a.kt)("strong",{parentName:"p"},"67"),", you see the placeholder ",(0,a.kt)("strong",{parentName:"p"},"{{varnish_proxy_pass}}"),"."),(0,a.kt)("p",null,"When ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," is disabled, the rendered value for this placeholder is:"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"proxy_pass http://127.0.0.1:8080;\n")),(0,a.kt)("p",null,"When ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache")," is enabled, it uses the value of ",(0,a.kt)("strong",{parentName:"p"},"Varnish Server")," from the ",(0,a.kt)("a",{parentName:"p",href:"../../settings"},"Varnish Cache Settings"),", e.g.,"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-bash"},"proxy_pass http://127.0.0.1:6081;\n")),(0,a.kt)("p",null,"Lines ",(0,a.kt)("strong",{parentName:"p"},"48-64")," are special for ",(0,a.kt)("strong",{parentName:"p"},"WordPress/WooCommerce"),". "),(0,a.kt)("p",null,"All requests to ",(0,a.kt)("strong",{parentName:"p"},"/wp-admin/")," and ",(0,a.kt)("strong",{parentName:"p"}
1,"wp-login.php")," are bypassed, meaning they are ",(0,a.kt)("strong",{parentName:"p"},"NOT")," going through ",(0,a.kt)("strong",{parentName:"p"},"Varnish Cache"),"; they are forwarded to port ",(0,a.kt)("strong",{parentName:"p"},"8080")," (see lines ",(0,a.kt)("strong",{parentName:"p"},"99-134"),"),\nwhere they get processed by the ",(0,a.kt)("strong",{parentName:"p"},"PHP Application")," via ",(0,a.kt)("strong",{parentName:"p"},"PHP-FPM"),"."),(0,a.kt)("iframe",{width:"100%",frameborder:"0",height:"3400",src:"data:text/html;charset=utf-8, <head><base target='_blank' /></head><body><script src='https://gist.github.com/cloudpanel-io/5921a28790f2718cc66b3f0c670a57a5.js'><\/script></body>"}))}u.isMDXComponent=!0},6010:(e,t,r)=>{function n(e){var t,r,a="";if("string"==typeof e||"number"==typeof e)a+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(r=n(e[t]))&&(a&&(a+=" "),a+=r);else for(t in e)e[t]&&(a&&(a+=" "),a+=t);return a}function a(){for(var e,t,r=0,a="";r<arguments.length;)(e=arguments[r++])&&(t=n(e))&&(a&&(a+=" "),a+=t);return a}r.d(t,{Z:()=>a})}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.