[英]NUXT when is each dist folder used, html/.nuxt/dist/ html/dist/_nuxt/ html/static html/assets?
If I use: Nuxt @ v2.15.8如果我使用:Nuxt @ v2.15.8
Environment: production环境:生产
Rendering: server-side渲染:服务器端
Target: server目标:服务器
In this case, which of all assets folders does NUXT use?在这种情况下,NUXT 使用所有资产文件夹中的哪个? Does NUXT in this case serve the assets from html/.nuxt/dist/ not from html/dist/_nuxt/ or html/static or html/assets?在这种情况下,NUXT 是否提供来自 html/.nuxt/dist/ 的资产,而不是来自 html/dist/_nuxt/ 或 html/static 或 html/assets 的资产? And what is the purpose of each different dist folder?每个不同的 dist 文件夹的目的是什么?
I can see that all my file names have the same names in html/.nuxt/dist/ as all missing 404 files in chrome dev (example.com/_nuxt/example1234.js), that's why I'm confused.我可以看到我的所有文件名在 html/.nuxt/dist/ 中与 chrome dev 中所有丢失的 404 文件(example.com/_nuxt/example1234.js)具有相同的名称,这就是我感到困惑的原因。
I now ran /nuxt start --port 3003 but normally pm2 start -- --port 3003. Same issue with both commands: all assets get 404.我现在运行 /nuxt start --port 3003 但通常是 pm2 start -- --port 3003。这两个命令都有同样的问题:所有资产都得到 404。
To clarify: I only get issues with missing files on the live Ubuntu 20.04 NGINX server, not locally in Windows 11.澄清一下:我只在实时 Ubuntu 20.04 NGINX 服务器上遇到丢失文件的问题,而不是在 Windows 11 本地。
I also tried now to set publicPath: 'example.com/cdn', and copied the content in /var/www/example.com/html/.nuxt/dist/client to /var/www/example.com/html/cdn but when I check the server error.log it says: " "/var/www/example.com/html/.nuxt/dist/cdn/85451fa.js" failed (2: No such file...." I even now copied the same files to /var/www/example.com/html/.nuxt/dist/cdn but even after that I get 404 on all assets. I even did sudo chmod -R 755 /var/www/example.com/html/cdn In Chrome it's correct URL example.com/cdn/85451fa.js我现在也尝试设置publicPath:'example.com/cdn',并将/var/www/example.com/html/.nuxt/dist/client中的内容复制到/var/www/example.com/html/ cdn 但是当我检查服务器 error.log 时它说:“”/var/www/example.com/html/.nuxt/dist/cdn/85451fa.js”失败(2:没有这样的文件......”我即使现在将相同的文件复制到 /var/www/example.com/html/.nuxt/dist/cdn 但即使在那之后我得到所有资产的 404。我什至做了 sudo chmod -R 755 /var/www/example。 com/html/cdn 在 Chrome 中是正确的 URL example.com/cdn/85451fa.js
So I get 404 in Chrome console on: https://example.com/_nuxt/c4ffa45.js But I can see that the file exists here: /var/www/example.com/html/.nuxt/dist/client/c4ffa45.js so I did: sudo chmod -R 755 /var/www/example.com/html/.nuxt/dist But still 404. So the html of the NUXT start page is served by PM2 but no scripts or images.所以我在 Chrome 控制台中得到 404: https://example.com/_nuxt/c4ffa45.js但我可以看到该文件存在于此处:/var/www/example.com/html/.nuxt/dist/client/ c4ffa45.js 所以我做了: sudo chmod -R 755 /var/www/example.com/html/.nuxt/dist 但仍然是 404。所以 NUXT 起始页的 html 由 PM2 提供,但没有脚本或图像。 Any idea why?知道为什么吗?
So do I use correct folders in NGINX config here if I run the project as Server Side Rendered ssr: true for SEO, and target: server如果我将项目作为服务器端渲染 ssr: true for SEO 和 target: server 运行,那么我是否在此处使用 NGINX 配置中的正确文件夹
server {
server_name www.example.com;
# www to non-www for SEO canonical reasons
return 301 http://example.com$request_uri;
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name example.com;
location / {
proxy_pass http://localhost:3003;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
root /var/www/example.com/html;
index index.html index.php index.htm index.nginx-debian.html;
# PHP
##location ~ \.php$ {
##include snippets/fastcgi-php.conf;
##fastcgi_pass unix:/run/php/php7.4-fpm.sock;
##}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location /_nuxt/ {
alias /var/www/example.com/html/.nuxt/dist/client/;
}
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|webp)$ {
rewrite ^/_nuxt(/.*) $1 break;
root /var/www/example.com/html/.nuxt/dist/client;
expires 24h;
add_header Cache-Control private;
}
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|webp)$ {
root /var/www/example.com/html/static;
expires 24h;
add_header Cache-Control private;
}
# (For WordPress permalinks)
#location / {
#try_files $uri $uri/ /index.php$is_args$args;
#}
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name test.example.com;
# ssl_* directives here
root /var/www/example.com/test;
index index.php index.html index.htm index.nginx-debian.html;
# PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
} location = /favicon.ico {
log_not_found off; access_log off;
} location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|webp)$ {
expires 24h;
add_header Cache-Control private;
}
# (For WordPress permalinks)
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com;
return 404; # managed by Certbot
}
server {
if ($host = test.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name test.example.com;
return 404; # managed by Certbot
}
My ecosystem.config.js looks like below:我的 ecosystem.config.js 如下所示:
module.exports = {
apps: [
{
name: 'app',
exec_mode: 'cluster',
instances: 'max', // Or a number of instances
script: './node_modules/nuxt/bin/nuxt.js',
cwd: '/var/www/example.com/html',
args: 'start',
env: {
NODE_ENV: "production",
PORT: 3003,
},
}
]
}
To run I use:要运行我使用:
yarn nuxt build
pm2 start -- --port 3003
It finally works!它终于奏效了!
This is what I did:这就是我所做的:
sudo ufw allow 3003
pm2 stop nuxtAppName
pm2 start -- --port 3003
You might also need to do:您可能还需要执行以下操作:
pm2 delete nuxtAppName
pm2 save
yarn nuxt generate
cd /var/www/example.com/nuxtAppDir
pm2 start ecosystem.config.js -- --port 3003
I would still like to know the different purposes of all the different directories because I now always need to manually copy assets from /var/www/example.com/release1/.nuxt/dist/client to /var/www/example.com/release1/dist/_nuxt on every new deploy我仍然想知道所有不同目录的不同用途,因为我现在总是需要手动将资产从 /var/www/example.com/release1/.nuxt/dist/client 复制到 /var/www/example.com /release1/dist/_nuxt 在每个新部署上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.