Repository navigation
Deployment to Linux server #14059
Replies: 1 comment 2 replies
|
Hi, thanks for starting this discussion! This is tricky because there is no preferred approach, and given all the possibilities, we cannot be exhaustive. As you noted, for a fully static website, For hybrid or on-demand rendered websites: So it's true that currently, deployment guides focus solely on deployment services. We can't cover all this: we only document what is specific to Astro to reduce maintenance cost. Perhaps we could add a section on the Deployment overview to provide minimal guidance (ie. links to the Docker recipe and Node adapter) for solutions such as VPS or shared hosting. As for complete instructions, I'm more hesitant. We could consider adding a new recipe, but I'm not sure there's an approach that's universal enough to be a good recipe. However, we always appreciate community blog posts explaining how someone did something! Once published, this could also be linked from Astro Tips, a community website. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I was surprised to see that the deployment guide explains how to deploy to a bunch of "fancy" services, but doesn't explain anything about how to deploy to a regular Linux server. The closest thing is the Hostinger guide, which says to use FTP using FileZilla for a static site, or deploy from Git (or manually upload) for a site with dynamic parts.
I'd like to contribute a guide that uses rsync, Nginx, and systemd. However, I'm trying to understand the best approach to take to deploy an Astro site.
For a purely static site, it's easy:
rsyncthedistdirectory to the server, then configure it like any other static site in Nginx.For a site with on-demand or server-rendered site, it's more difficult. We can use systemd to run the server-side code, but getting it into a state where it can run on the server is what I'm trying to figure out.
With C#, I run
dotnet publishand the resultingpublishdirectory contains everything that's needed on the production site - compiled C# app, dependencies, and the built JS and CSS for the site. I thoughtastro buildwould perform similarly, but the server-side code indistisn't standalone as it still requiresnode_modules.I was thinking of some approaches:
rsyncthe entire site (or check it out using Git) then useastro buildon the server. It works, but it's not great... A production server shouldn't also be a build environment.esbuildor similar to build the server into a single JS file. This could be combined with Node SEA (single executable applications) to build the site into a single executable. I haven't tried it.distto the server, copy acrosspackage.jsonand the lock file, and runnpm install --omit=devto only install the packages that are required in prod.The last one seems like the most reasonable approach. It's still not perfect since the production server needs to have npm on it, but it's not too bad. It would be useful if Astro could copy the package.json file to the
distdirectory itself rather than me having to do that.Does the Astro team have a preferred approach for deploying to a regular server?
All reactions