gogogo
管理员
管理员
  • UID25
  • 粉丝0
  • 关注0
  • 发帖数1416
阅读:91回复:0

ruoyi部署到服务器后 前端接口 报 520 ,个人解决方式

楼主#
更多 发布于:2025-05-15 17:12
ruoyi部署到服务器后  前端接口 报 520
是因为 nginx 配置的问题
nginx :
server {
    listen      80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
            root /usr/share/nginx/html;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
            error_page 405 =200 @405;  #405页面处理

   proxy_buffer_size 64k;
            proxy_buffers   32 32k;
            proxy_busy_buffers_size 128k;

     proxy_set_header Host $host;
            proxy_set_header X-Real-IP       $remote_addr;
            proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
       }
 
        #加入下面代码
       location @405 {
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
             #ip为后端服务地址
             proxy_pass http://localhost:8080$request_uri ;
       }

# 配置代理 要和你的后端对应上
    # 服务器访问时,f12进入检查时会自动带上的prod-api前缀,要和你的后端对应上
    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;
        # 填写的内容要与若依前端代码中的target中的地址一致 (注意写IP服务器地址 ,不是 http://localhost:8080/  跟spring-boot 后端代码中一致即可 )

     proxy_pass http://10.57.9.72:8080/;  
     proxy_connect_timeout 6000s;
     proxy_read_timeout  6000s;
     proxy_send_timeout  6000s;
proxy_ssl_server_name on;
# 作用域 http、server、location
proxy_http_version 1.1;
proxy_set_header Connection "";

    }

    location /openTime/ {
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;
         # 填写的内容要与若依前端代码中的target中的地址一致(注意写服务器IP地址 ,不是 http://localhost:5050/  跟spring-boot 后端代码中一致即可 proxy_pass http://10.32.23.141:5050/; proxy_connect_timeout 6000s;
     proxy_read_timeout  6000s;
     proxy_send_timeout  6000s;
proxy_ssl_server_name on;
# 作用域 http、server、location
proxy_http_version 1.1;
proxy_set_header Connection "";
     }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}



保存后 重启nginx

张翱翔  2025-05-15
游客


返回顶部