vue.js - konfigurasi nginx selepas vue-router menghidupkan mod sejarah HTML5
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 17:15:13
0
2
1134

Oleh kerana terdapat banyak subprojek di bawah projek eagle201510, saya mencuba pelbagai kaedah konfigurasi tetapi ia tidak dapat wujud bersama

Saya harap begitu:

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-example目录是使用vue-router开发的单页应用,需要单独配置,但这种方式m-example并不能正常加载
加载的js,css都变成了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".

Jika konfigurasi ditukar kepada ini:

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;
        }
}

Ia perkara biasa. Tetapi projek lain tidak dapat diakses. . .

曾经蜡笔没有小新
曾经蜡笔没有小新

membalas semua(2)
过去多啦不再A梦

Tambahkan server item konfigurasi untuk menyelesaikan masalah, seperti berikut:

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;
        }
}
过去多啦不再A梦

Lompat ke index.html untuk semua permintaan tanpa akhiran jika 404

location / {
  error_page  404  /index.html; 
}
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan