Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部署了服务之后前端请求报错 #1

Open
wick233 opened this issue Nov 7, 2024 · 2 comments
Open

部署了服务之后前端请求报错 #1

wick233 opened this issue Nov 7, 2024 · 2 comments

Comments

@wick233
Copy link

wick233 commented Nov 7, 2024

登录的时候报错,这种是什么情况
{
"code": 1,
"message": "No static resource api/public/user/login/password.",
"data": null
}
这个是nginx里面的配置文件
server {
server_name vue.855550.xyz;
listen 443 ssl;

ssl_certificate /etc/letsencrypt/live/vue.8550.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/vue.8550.xyz/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

root /var/www/html/dist;  # 前端构建目录
index index.html;

# 其他路径返回前端页面
location / {
    try_files $uri $uri/ /index.html;
}

# 静态资源缓存配置
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
    expires 1y;
    access_log off;
    add_header Cache-Control "public, no-transform";
    try_files $uri =404;  # 如果资源不存在,则返回 404
}

# 转发所有 /api 请求到后端
location /api {
    proxy_pass http://localhost:8080;  # 转发到后端
    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_set_header X-Forwarded-Proto $scheme;
}

}

server {
if ($host = vue.8550.xyz) {
return 301 https://$host$request_uri;
}
server_name vue.855550.xyz;
listen 80;
return 404;
}

@wick233
Copy link
Author

wick233 commented Nov 7, 2024

[root@localhost ~]# curl http://localhost:8080/public/menu?type=0
{"code":1,"message":"操作失败!","data":null}
在终端上试了下,接口能正常返回

@dawnstaryrx
Copy link
Owner

详细的部署文档以及docker部署我最近会更新,你可以先看一下我的nginx配置
部署的时候用Nginx做反向代理,Nginx 配置中需要将 /api 路径转发到了后端服务器

server {

	location /api {
	    rewrite ^/api/(.*)$ /$1 break;
	    proxy_pass http://124.221.89.196:8080;
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants