RuoYi若依部署前端时,nginx配置错误解决
需要部署 若依RuoYi-Vue前后端分离的后台管理系统时,后端正常,但是前端保存。
若依的地址:https://doc.ruoyi.vip/ruoyi-vue/
前端需要nginx,在windows10系统上,nginx部署运行正常。
但是RuoYi-Vue前端部署在端口7079,运行报错。
nginx保存信息的log文件内容如下:
uoyi-ui/index.html" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1:7079", referrer: "http://127.0.0.1:7079/"
2025/03/28 12:34:23 [crit] 9428#11860: *5 GetFileAttributesEx() "E: emp
uoyi-ui/index.html" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: localhost, request: "GET /index HTTP/1.1", host: "127.0.0.1:7079"
2025/03/28 12:46:04 [crit] 9428#11860: *9 GetFileAttributesEx() "E: emp
uoyi-ui/index.html" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: localhost, request: "GET /index HTTP/1.1", host: "127.0.0.1:7079"
2025/03/28 12:46:04 [crit] 9428#11860: *9 GetFileAttributesEx() "E: emp
uoyi-ui/index.html" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: localhost, request: "GET /index HTTP/1.1", host: "127.0.0.1:7079"
2025/03/28 12:46:04 [crit] 9428#11860: *9 GetFileAttributesEx() "E: emp
uoyi-ui/index.html" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: localhost, request: "GET /index HTTP/1.1", host: "127.0.0.1:7079"
2025/03/28 12:46:04 [error] 9428#11860: *9 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: localhost, request: "GET /index HTTP/1.1", host: "127.0.0.1:7079"
经分析,是windows下的nginx的配置信息存在错误,关键信息如下:
server {
listen 7079;
server_name localhost;
charset utf-8;
location / {
root E:\temp\ruoyi-ui;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8081/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
里面的目录E:\temp\ruoyi-ui
就是前端部署文件,经分析,应采用正斜杠/,也就是正确的应该是:
E:/temp/ruoyi-ui
修改nginx配置后,正常运行如下: