search

Home  >  Q&A  >  body text

vue.js - nginx configuration after vue-router turns on HTML5 history mode

Because there are many sub-projects under the eagle201510 project, I have tried multiple configuration methods but they cannot coexist

I hope it is like this:

server {
        listen       80;
        server_name  192.168.10.91;
        root   "E:/UED/eagle/branch/eagle201510";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ^~ /m-example/ {
            root   "E:/UED/eagle/branch/eagle201510/m-example";
            try_files $uri $uri/ /index.html =404;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

m-exampleThe directory is a single-page application developed using vue-router and needs to be configured separately, but this way m-example cannot be loaded normally
js and css have become html
console

vendors.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <
index.html:6 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://192.168.10.91/m-example/dist/main.css".

If the configuration is changed to this:

server {
        listen       80;
        server_name  192.168.10.91;
        root   "E:/UED/eagle/branch/eagle201510";
        location / {
            root   "E:/UED/eagle/branch/eagle201510/m-example";
            try_files $uri $uri/ /index.html =404;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

is normal. But other projects are inaccessible. . .

曾经蜡笔没有小新曾经蜡笔没有小新2757 days ago1117

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 17:17:13

    Add a server configuration item to solve the problem, as follows:

    server {
            listen       80;
            server_name  www.m-example.com;
            root   "E:/UED/eagle/branch/eagle201510/m-example";
            location / {
                try_files $uri $uri/ /index.html =404;
            }
    }

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 17:17:13

    Jump to index.html for all requests without suffix if 404

    location / {
      error_page  404  /index.html; 
    }

    reply
    0
  • Cancelreply