题目描述
nuxt项目bulid打包放到服务器之后出现js404,站点图标不见
题目来源及自己的思路
相关代码
package.json
{
"name": "ihccs-uzhi-seo",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint:prettier": "prettier --check .",
"lint": "yarn lint:prettier",
"lintfix": "prettier --write --list-different ."
},
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
"core-js": "^3.19.3",
"element-ui": "^2.15.6",
"nuxt": "^2.15.8",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"webpack": "^4.46.0"
},
"devDependencies": {
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.5.1"
}
}
nuxt.config.js
export default {
// Global page headers: https://go.nuxtjs.dev/config-...
head: {
title: 'ihccs-uzhi-seo',
htmlAttrs: {
lang: 'en',
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' },
],
link: [{ rel: 'icon', type: 'image/x-icon', href: './favicon.ico' }],
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: ['element-ui/lib/theme-chalk/index.css'],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-...
plugins: ['@/plugins/element-ui'],
// Auto import components: https://go.nuxtjs.dev/config-...
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-...
buildModules: [],
// Modules: https://go.nuxtjs.dev/config-...
modules: [
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
],
server: {
port: 12345, // default: 3000
host: '0.0.0.0', // default: localhost
},
// Axios module configuration: https://go.nuxtjs.dev/config-...
axios: {
// Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
baseURL: '/',
},
// Build Configuration: https://go.nuxtjs.dev/config-...
build: {
transpile: [/^element-ui/],
},
}
nginx配置(多个项目都在此文件,我的这个项目是最后一个pctest.uzhijob.com)
server {
listen 80;
server_name uzhi.ihccs.com;
rewrite ^(.*) https://$host$1 permanent;
}
server{
listen 80;
server_name test.ulz.uzhijob.com;
root '/usr/www/ulz_mobile';
location / {
try_files $uri $uri/ /index.html;
}
location /Url {
proxy_pass https://open.ihccs.com/test;
}
}
server {
listen 80;
server_name uzhi1.ihccs.com;
root '/usr/www/uzhi-Pc/public';
index index.php index.html index.htm;
charset utf-8;
ssl_certificate /usr/local/nginx/ssl/uzhi.ihccs.com.pem;
ssl_certificate_key /usr/local/nginx/ssl/uzhi.ihccs.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
#location /static {
# root '/usr/www/uzhi-Pc/public/ad';
# try_files $uri $uri/ /index.html;
#}
location /Url {
proxy_pass 'https://open.ihccs.com/test';
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
# 日志,指定路径后可选开启。末尾值可选 error|notice|info
# error_log /var/log/nginx/xxx.com-error.log error;
sendfile off;
server_tokens off;
#client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# 如果用到 sock 则值参考 unix:/var/run/php/php7.0-fpm.sock
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name mobile.test.ihccs.com;
location / {
root '/usr/www/ihccs_mobile';
index index.html index.htm;
}
location /openApi {
index index.html;
proxy_pass https://open.ihccs.com/test/;
proxy_hide_header ETag;
}
location /ihccsMobile {
index index.html;
proxy_pass https://www.ihccs.com/api;
proxy_hide_header ETag;
}
location /Uploads {
index index.html;
proxy_pass https://www.ihccs.com/Uploads;
proxy_hide_header ETag;
}
#error_page 404
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
#listen [::]:80;
server_name pctest.uzhijob.com;
index index.html index.htm index.php default.html default.htm default.php;
#root /home/wwwroot/shudong.wang; #在nuxt 动态不需要配置,静态的可以指定
#include other.conf;
#error_page 404 /404.html;
#include enable-php.conf;
location / {
#alias /www/wwwroot/pctest.uzhijob.com/uzhi;
添加这3行
proxy_buffer_size 64k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://localhost:12345;
proxy_redirect off;
try_files $uri $uri/ /index.html;
}
# 注意要和项目中配置的base一样
location ^~/admin {
alias /www/wwwroot/pctest.uzhijob.com/admin;
try_files $uri $uri/ @rewrites;
}
#location @rewrites {
# rewrite ^/(admin)/(.+)$ /$1/index.html last;
#}
#err_log /www/wwwlogs/pctest.log;
}