0
server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root /var/www/vue/dist;

    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
        add_header "GET, POST, HEAD" always;

    location /static {
        alias /var/www/vue/dist/static/;
    }

    location /web/service {
        if ($request_method = OPTIONS ) {
              return 405;
        }
        rewrite ^/web/service/(.*)$  /$1  break;
        try_files $uri $uri/   /index.html;
        autoindex off;
        index   index.html;
    }

}

I developed the frontend using vue. After the build, I try to load the page in /web/service, but the js file is not loaded.

I am getting a 404 error.

The built file is located under /var/www/vue/dist and the configuration is as follows.

dist
  -- index.html
  -- static
     -- css
     -- js
     -- font

The dist file is structured like this.

The static subfiles are not loaded.

In the console window

GET https://{URL}/static/js/app.4d37ce819e144.js net::ERR_ABORTED 404 (Not Found)

output like this

But https://{URL}/web/service/static/js/app.4d37ce819e144.js If you type in the address bar, the contents of the file are displayed.

I hope you can tell me how to configure nginx.

Jeet Patel
  • 1,140
  • 18
  • 51
  • Try removing the entire `location /static { alias /var/www/vue/dist/static/; }` block. – Richard Smith Jun 02 '21 at 08:25
  • The alias was removed, but that was not the way. There is a setup that adds prefix when building frontend, and there it is done by adding web/v1.. this part. – rlawlgus322 Jul 16 '21 at 04:36

0 Answers0