首页 > 解决方案 > 如何使用 nginx 使 vue 项目中的 css 和 js 文件在生产中工作

问题描述

我的 Vue 项目是我在 Ubuntu 18.04 中的路径 vue

/var/www/html/vue/{ project here }

问题是我的 css 路径是/css/var/www/html/css 如何在 vue 项目中设置我的 css 在文件夹中参考这里是我的 nginx 设置

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 ssl;
    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    location /vue {
        // I try to make root path but It's not workking error 500 when I uncomment #root
           #root /var/www/html/vue;
           try_files $uri $uri/ /vue/index.html;
    }
}

标签: vue.jsnginx

解决方案


您可以使用当前配置尝试以下操作:

 location /css {
    alias /var/www/html/css;
 }

推荐阅读