vue-element-admin+laravel10前后端分离项目,部署到服务器,后端接口404,location没生效?

用的是宝塔面板,nginx是1.15
以下是nginx配置

server

{

listen 80;

server_name test.cn;

index index.php index.html index.htm default.php default.htm default.html;

root /www/wwwroot/web-admin/dist/;

#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则

#error_page 404/404.html;

#SSL-END

#ERROR-PAGE-START 错误页配置,可以注释、删除或修改

#error_page 404 /404.html;

#error_page 502 /502.html;

# 默认访问前端项目

location / {

#解决页面刷新404问题

try_files $uri $uri/ /index.html;

}

# 后端项目

location ~ ^/(admin-api) {

try_files $uri $uri/ /index.php?$query_string;

}

#ERROR-PAGE-END

#PHP-INFO-START PHP引用配置,可以注释或修改

include enable-php-81.conf;

location ~ \.php(.*)$

{

root /www/wwwroot/api-admin/public/;

try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi-81.sock;

fastcgi_index index.php;

include fastcgi.conf;

include pathinfo.conf;

}

#PHP-INFO-END

#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效

include /www/server/panel/vhost/rewrite/test.cn.conf;

#REWRITE-END

#禁止访问的文件或目录

location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)

{

return 404;

}

#一键申请SSL证书验证目录相关设置

location ~ \.well-known{

allow all;

}

#禁止在证书验证目录放入敏感文件

if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {

return 403;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

error_log /dev/null;

access_log /dev/null;

}

location ~ .*\.(js|css)?$

{

expires 12h;

error_log /dev/null;

access_log /dev/null;

}

# 前端静态资源处理

location ^~ /images/ {

alias /www/wwwroot/web-admin/dist/images/;

}

# 后端静态资源处理

location ^~ /storage/ {

alias /www/wwwroot/api-admin/public/storage/;

}

access_log /www/wwwlogs/test.cn.log;

error_log /www/wwwlogs/test.cn.error.log;

}

server {

listen 9527;

server_name localhost;

# 接口代理,用于解决跨域问题

location /admin-api {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# 后台接口地址

# proxy_pass http://127.0.0.1:9527/admin-api;

# proxy_redirect default;

# add_header Access-Control-Allow-Origin *;

# add_header Access-Control-Allow-Headers X-Requested-With;

# add_header Access-Control-Allow-Methods GET,POST,PUT,PATCH,DELETE,OPTIONS;

}

}

我如果在location / {alias /www/wwwroot/web-admin/dist/;}这样写首页会空白,css,js文件会报404,只能写在外面,然后那个拦截到admin-api的请求的判断,也不生效,接口都会404,求教!
 vue-element-admin+laravel10前后端分离项目,部署到服务器,后端接口404,location没生效?

以上是 vue-element-admin+laravel10前后端分离项目,部署到服务器,后端接口404,location没生效? 的全部内容, 来源链接: utcz.com/p/934888.html

回到顶部