Nuxt.js: Document serving static files with nginx (with SSR backend)

Created on 8 Jan 2018  ·  33Comments  ·  Source: nuxt/nuxt.js

Currently Nuxt.js uses serve-static as a middleware for static files. This can be offloaded to nginx for efficiency.

Basically, the code here needs to be documented.

This feature request is available on Nuxt.js community (#c2186)
documentation enhancement pending

Most helpful comment

This issue is still valid.

All 33 comments

Wrong, please reopen. I'm not asking for configuring serve-static, I want to serve the static files on nginx.

If you want to serve static files on nginx, you can just move static to nginx and config the proxy.

 location /staticx/ {
        root /www/static;
  }

Is there any concerns ?

Please read the issue content.

Serving static files directly to nginx has nothing to do with the nuxt or node side, it must be done with the nginx config. There are multiple ways to achieve this, like selecting the types of files that you want to directly serve. Here is an example:

```
location ~* ^.+.(jpg|svg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
gzip on;
expires 365d;
root /absolute/path/to/sourcefiles/static;
}
````

Hey, please read the description thoroughly before commenting.

I'm talking about documenting which file are served (through serve-static) under _nuxt/. Undocumented thing may change and break any time, so documenting allows me to reliably move this job to nginx.

Also, it's not a simple path mount currently, but it also requires several filters so the server side source would not be revealed. Those needs to be either refactored to be moved out, or documented to be ignored.

Well, we have another option: copy the static files to dist/ just like SPA or generate mode do.

This is safer because we can change the internal behavior at any time, but a drawback is that it may be confusing to users (they may think it's completely static but it's not).

Well, my goal would be to have Nothing more to do than a build and restart the app, with an automated process. Needing to manually select some files from different folders (static, .nuxt/dist, root...) is a big downside to me…

Did you manage to use ngnix to serve the static files?

Totally agree with @ishitatsuyuki
The documentation is very confusing about serving static files...
I'll give it a look whether I could improve that part.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This is still a valid issue.

@LeoMartinDev You can always disable that behavior ☺️

@ishitatsuyuki I see the point here. Documentation of the files served (and the excluded ones) would be appreciated, I agree.

To provide an update, we no longer need the exclusion because we now put them into a separate directory. It's much simpler, just need a documentation (and maybe changelogs) on which directory we should mount.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue is still valid.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 🕐Pending will not be automatically marked as stale.

The bot is malfunctioning.

What a pity to see most of the SSR websites on Showcase | Awesome Nuxt.js did not GZIP their JS / CSS, which results in enormous network loads. Some of them are running serious business, not for demo purposes.

The developers of these websites might have already configured gzip on on nginx.conf according to https://nuxtjs.org/faq/nginx-proxy . However, as you see, it's not working at all.

We tend to trust the official docs and we sincerely appreciate Nuxt team's hard work. However, Nuxt team should also test the functions before writing docs. Maybe it should be a caveat about GZIP on FAQ refers to https://github.com/nuxt/nuxt.js/issues/105 and this issue.

@kenberkeley I picked a random sample of 10 sites out of the showcases and all had either GZIP or Brotli encoding enabled. Please double-check 😉

The deployment of a Nuxt app is up to the user. We can't set up NGINX/Apache for every use-case and can only provide ideas/configs that work in most of the cases.

Regarding the linked config itself, @pimlie can give you more info about that ☺️

@manniL You should double-check. I picked ramdom sample of 10 sites and none of them had GZIP.

All Request Headers include accept-encoding: gzip, deflate, br while all Response Headers do not include content-encoding: gzip / br .

Don't trust me, but verify, please.

image

@kenberkeley must be on your side.

image

Also, when you download the JS file, you always download the "uncompressed" version.

WT...

Incognito mode, got the same result... Emmm... Maybe my Chrome broke...

image

@kenberkeley The size of the file doesnt change due to gzip compression. Gzip compression is part of the http protocol to reduce transfer size, as soon as the file hits your browser the file is decompressed and saved in its normal format. So I think you are just looking at the wrong info, eg look at @manniL's screenshots and you will see that his size column also says 466KB for the vendor bundle, but the transferred size is lower due to gzip compression.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 🕐Pending will not be automatically marked as stale.

Is this issue rendered obsolete with nuxt export?

Is this issue rendered obsolete with nuxt export?

Not necessarily, because it's mostly related to a deploy with a Node.js server (nuxt build && nuxt start)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  ·  3Comments

pehbehbeh picture pehbehbeh  ·  3Comments

surmon-china picture surmon-china  ·  3Comments

uptownhr picture uptownhr  ·  3Comments

maicong picture maicong  ·  3Comments