vue+laravel搭建遇到404,405

1,环境是phpstudy
laravel5.8 -地址:https://learnku.com/docs/laravel/5.8/deployment/3884#nginx
php 7.2.9
nginx
composer 1.8.5
node v12.16.2
nmp 6.14.4
2,nginx 配置加:
server {
listen 5020;
server_name localhost;
root "B:/phpstudy_pro1/WWW/***/public";
location / {
index index.php index.html error/index.html;
try_files $uri u r i / / i n d e x . p h p ? uri/ /index.php? uri//index.php?query_string; 配置不好报404
error_page 400 /error/400.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 500 /error/500.html;
error_page 501 /error/501.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;
error_page 504 /error/504.html;
error_page 505 /error/505.html;
error_page 506 /error/506.html;
error_page 507 /error/507.html;
error_page 509 /error/509.html;
error_page 510 /error/510.html;
autoindex off;
}
location ~ .php(.
)$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root documentrootfastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED d o c u m e n t r o o t document_root documentrootfastcgi_path_info;
include fastcgi_params;
}
}
3,localhost 配置laravel根目录端口指向80,没有指向5020,报错405
4,vue加信息

vue 目录下 www\config\index.js

module.exports = {
dev: {
// Paths
assetsSubDirectory: ‘static’,
assetsPublicPath: ‘/’,
proxyTable: { // 代理配置信息
‘/api’: {
target: ‘http://127.0.0.1:5020’, // API服务所在IP及端口号
changeOrigin: true, // 如果设置为true,那么本地会虚拟一个服务器接收你的请求并代你发送该请求,这样就不会有跨域问题(只适合开发环境)
pathRewrite: {
‘^/api’: ‘’ // 重写路径
}
}
},
5,vue加信息 www\config\dev.env.js

module.exports = {
NODE_ENV: ‘“development”’,
ENV_CONFIG: ‘“dev”’,
BASE_API: ‘“http://127.0.0.1:5020”’//本地服务器地址
}

6,vue加信息
www\src\utils\request.js

// create an axios instance
let baseUrl=’’
process.env.ENV_CONFIG === ‘dev’? baseUrl = ‘/api’:baseUrl = process.env.BASE_API
const service = axios.create({
baseURL: baseUrl, // api的base_url
timeout: 20000 // request timeout
})

7,配置数据库信息
.env和laravel下config/database.php

8,记得加数据库

你可能感兴趣的:(Laravel)