{"id":16922,"date":"2024-11-20T15:02:21","date_gmt":"2024-11-20T20:02:21","guid":{"rendered":"https:\/\/kb.n0c.com\/?post_type=ht_kb&#038;p=16922"},"modified":"2024-11-20T15:03:19","modified_gmt":"2024-11-20T20:03:19","slug":"how-to-serve-the-static-content-of-your-application","status":"publish","type":"ht_kb","link":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/","title":{"rendered":"How to Serve the Static Content of Your Application"},"content":{"rendered":"\n<p>This article explains how to make sure that the static content of your Node.js, Ruby or Python application is served by the server.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">The <a href=\"https:\/\/kb.n0c.com\/en\/glossary\/\">glossary<\/a> contains explanations on a wide range of subjects and can be consulted to clarify certain terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Enter the following address in your web browser: https: <a href=\"https:\/\/mg.n0c.com\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">\/\/mg.n0c.com\/en\/<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>N0C servers use Passenger to run your Node.js, Ruby and Python web applications.<\/p>\n\n\n\n<p>One of the philosophies of Passenger is to take into account the fact that, in practice, many web applications share the same conventions with regard to structural characteristics. Among other things, most web applications have a directory in which they store static files.<\/p>\n\n\n\n<p>To make life easier, Phusion Passenger \u201cassumes\u201d these conventions by default so that, if your application conforms to them, you will get a lot of out-of-the-box functionalities, without any configuration. In the case of Node.js, for example, Passenger considers that your application directory has the following structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>directory of your application\n  |\n  +-- app.js\n  |\n  +-- public\/\n  |\n  +-- tmp\/<\/code><\/pre>\n\n\n\n<p>Where :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>app.js<\/code> is the entry point for your Node.js application. Phusion Passenger starts your application by loading this file. It must register a request handler, as we will see later;<\/li>\n\n\n\n<li>the <code>public<\/code> directory contains static files that are automatically served by the web server. For example, if there is a <code>public\/image.jpg<\/code> file, all requests to <code>\/image.jpg<\/code> will be processed by the web server and never passed on to the application;<\/li>\n\n\n\n<li>the <code>tmp<\/code> directory can be used by the application, but is also used by Phusion Passenger to restart the application.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">In Ruby, <code>config.ru<\/code> is the entry point for your application. For Python, <code>run.py<\/code> is the entry point to use.<\/p>\n\n\n\n<p>All your the static files of your application, such as images, css files, js files, etc., should be stored in the <code>public<\/code> directory. In addition, you need to place an .htaccess file in which you can specify to add cache headers and their expiry time. In fact, if the htaccess remains in public_html, it will not be used for your application.<\/p>\n\n\n\n<p>To achieve this, you first need to prepare Phusion Passenger to serve the static content of your application. That is what this article is all about.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automatic Preparation of Passenger<\/h2>\n\n\n\n<p>Some steps are automatic and performed in the MG Panel:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>creation of directory structure;<\/li>\n\n\n\n<li>defining <code>app.js<\/code>, <code>config.ru<\/code> or <code>run.py<\/code> as the entry point for your application.<\/li>\n<\/ul>\n\n\n\n<p>The remaining steps are manual.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Manual Preparation of Passenger<\/h2>\n\n\n\n<p>Here are the manual steps you need to follow to get Phusion Passenger to serve and manage your application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 &#8212; Configure and Restart Your Application<\/h3>\n\n\n\n<p>Once you have configured your application in the language of your choice, simply restart it. This triggers the start-up of your Phusion Passenger application.<\/p>\n\n\n\n<p>Please refer to the following articles, which explain how to configure and restart your application:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/ruby-application-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Manage Ruby Applications<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/python-application-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Manage Python Applications<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/nodejs-application-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Manage Node.js Applications<\/a>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 &#8212; Create a Public Directory for Static Files<\/h3>\n\n\n\n<p>Create a <code>public<\/code> directory and move all static files into it.<\/p>\n\n\n\n<p>Please refer to the <a href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/n0c-filemanager\/#:~:text=file%20or%20folder.-,Move%20File,-Move%20a%20file\" target=\"_blank\" rel=\"noreferrer noopener\">paragraph explaining how to move a file in the article \u201cHow to use the file manager<\/a>\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3 &#8212; Place the .htaccess File in the Public Directory<\/h3>\n\n\n\n<p>By default, N0C storage contains a <code>public<\/code> directory. All you need to do is place the .htaccess file in it.<\/p>\n\n\n\n<p>You can find the folder containing the .htaccess of your application by going to the \u201cFile manager\u201d option on your N0C panel. On this page, you will be able to find all your domains as well as the root of the document linked to that domain.<\/p>\n\n\n\n<p>Please refer to the article <a href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/n0c-filemanager\/#:~:text=on%20the%20left.-,Distinction%20between%20the%20Public%20and%20Private%20folders,-By%20default%2C\" target=\"_blank\" rel=\"noreferrer noopener\">How to use the file manager<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">If a framework was used and it did not have a <code>public<\/code>folder generated (or if it had a different name, such as \u201cbrowser\u201d), you would need to create a symlink named <strong>public<\/strong> that would point to the <code>public<\/code> folder generated by the framework.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"documentation\"><strong>Documentation<\/strong><\/h2>\n\n\n\n<p>You can find documentation on the subjecton the Web, in particular at: <a href=\"https:\/\/github.com\/phusion\/passenger\/wiki\/Phusion-Passenger%3A-Node.js-tutorial#prepare-your-app\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/phusion\/passenger\/wiki\/Phusion-Passenger%3A-Node.js-tutorial#prepare-your-app<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explains how to make sure that the static content of your Node.js, Ruby or Python application is served by the server. Prerequisites Enter the following address in your web browser: https: \/\/mg.n0c.com\/en\/. Introduction N0C servers use Passenger to run your Node.js, Ruby and Python web applications. One of&#8230;<\/p>\n","protected":false},"author":4,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[163],"ht-kb-tag":[466,465],"class_list":["post-16922","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-languages","ht_kb_tag-n0c-passenger","ht_kb_tag-n0c-phusion-passenger"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Serve the Static Content of Your Application - N0C KB<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Serve the Static Content of Your Application - N0C KB\" \/>\n<meta property=\"og:description\" content=\"This article explains how to make sure that the static content of your Node.js, Ruby or Python application is served by the server. Prerequisites Enter the following address in your web browser: https: \/\/mg.n0c.com\/en\/. Introduction N0C servers use Passenger to run your Node.js, Ruby and Python web applications. One of...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/\" \/>\n<meta property=\"og:site_name\" content=\"N0C KB\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-20T20:03:19+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/how-to-serve-the-static-content-of-your-application\\\/\",\"url\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/how-to-serve-the-static-content-of-your-application\\\/\",\"name\":\"How to Serve the Static Content of Your Application - N0C KB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/#website\"},\"datePublished\":\"2024-11-20T20:02:21+00:00\",\"dateModified\":\"2024-11-20T20:03:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/how-to-serve-the-static-content-of-your-application\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/how-to-serve-the-static-content-of-your-application\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/how-to-serve-the-static-content-of-your-application\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/kb.n0c.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Serve the Static Content of Your Application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/#website\",\"url\":\"https:\\\/\\\/kb.n0c.com\\\/\",\"name\":\"N0C KB\",\"description\":\"Official documentation of the N0C hosting platform\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kb.n0c.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Serve the Static Content of Your Application - N0C KB","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/","og_locale":"en_US","og_type":"article","og_title":"How to Serve the Static Content of Your Application - N0C KB","og_description":"This article explains how to make sure that the static content of your Node.js, Ruby or Python application is served by the server. Prerequisites Enter the following address in your web browser: https: \/\/mg.n0c.com\/en\/. Introduction N0C servers use Passenger to run your Node.js, Ruby and Python web applications. One of...","og_url":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/","og_site_name":"N0C KB","article_modified_time":"2024-11-20T20:03:19+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/","url":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/","name":"How to Serve the Static Content of Your Application - N0C KB","isPartOf":{"@id":"https:\/\/kb.n0c.com\/#website"},"datePublished":"2024-11-20T20:02:21+00:00","dateModified":"2024-11-20T20:03:19+00:00","breadcrumb":{"@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/how-to-serve-the-static-content-of-your-application\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/kb.n0c.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/kb.n0c.com\/en\/knowledge-base\/"},{"@type":"ListItem","position":3,"name":"How to Serve the Static Content of Your Application"}]},{"@type":"WebSite","@id":"https:\/\/kb.n0c.com\/#website","url":"https:\/\/kb.n0c.com\/","name":"N0C KB","description":"Official documentation of the N0C hosting platform","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kb.n0c.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/16922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/comments?post=16922"}],"version-history":[{"count":6,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/16922\/revisions"}],"predecessor-version":[{"id":16928,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/16922\/revisions\/16928"}],"wp:attachment":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/media?parent=16922"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb-category?post=16922"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=16922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}