欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue history模式前后端分离项目nginx配置

程序员文章站 2022-06-13 19:11:11
...

项目配置

前端使用vue.js,路由mode为history,后端laravel请求统一为/api/*

nginx配置

wms.conf文件配置

server{
    listen 80;
    server_name testwms.com;
    index index.html index.php;
    error_log "E:/logs/nginx/wms/wms.error.log";
    access_log "E:/logs/nginx/wms/wms.access.log";
    set $fe_root_path "E:/project/wms_front/dist";
    set $rd_root_path "E:/project/wms/public";
    root $fe_root_path;

    location ^~ /api {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location / {
        try_files $uri $uri/  @router;
        index index.html;
    }

    location @router {
        rewrite ^.*$ /index.html last;
    }

    location ~ \.php {
       root          $rd_root_path;
       try_files    $uri =404;
       fastcgi_index  /index.php;
       fastcgi_pass   127.0.0.1:9000;
       include fastcgi_params;
       fastcgi_split_path_info       ^(.+\.php)(/.+)$;
       fastcgi_param PATH_INFO       $fastcgi_path_info;
       fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
       root $fe_root_path;
    }

    location ~ /\.ht {
       deny all;
    }
}
复制代码