在Nginx上部署VUE项目,找不到css,js之类的静态文件

时间:2020-01-03 10:40:08

标签: vue.js nginx

我的操作系统是窗口,并在Nginx服务器上部署VUE项目。

  1. 建立VUE项目 光盘E:\ test \ test-project-frontend-demo npm install && npm运行构建
  2. 配置nginx:

nginx.conf

worker_processes  1024;

pid                     logs/nginx.pid;

events {
    multi_accept        on;
    worker_connections  65535;
}

http {
    #MIME
    include             mime.types;
    default_type        application/octet-stream;

    #LOGGING
    log_format          main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';

    access_log          logs/access.log     main;
    error_log           logs/error.log      warn;

    charset             utf-8;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    server_tokens       off;
    log_not_found       off;
    types_hash_max_size 2048;
    client_max_body_size 16M;
    #keepalive_timeout  0;
    keepalive_timeout   65;
    gzip  on;

    #SITES
    include sites-available/project.conf;
}

project.conf

server {
    listen          80;
    listen          443 ssl;

    server_name project.testltd.com;

    # security
    include nginxconfig.io/security.conf;

    # logging
    access_log logs/project.access.log;
    error_log logs/project.error.log warn;

    # site project
    location / {
        alias E:/test/test-project-frontend-demo/dist;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    # additional config
    include nginxconfig.io/general.conf;

    # ssl config
    include nginxconfig.io/self-signed.conf;
    include nginxconfig.io/ssl-params.conf;
}

启动nginx: nginx.exe -c conf / nginx.conf

enter image description here

index.html可以访问,响应为200,但是无法访问css和js这样的静态文件,为什么?

0 个答案:

没有答案