JAVA前后端分离使用nginx部署验证码图片无法显示

sbeg571 2023-08-28 15:12:33

JAVA前后端分离使用nginx部署验证码图片无法显示,查找网上资料nginx配置文件修改但还是不显示

F12有报错:data:image/gif;base…:1     Failed to load resource: net::ERR_INVALID_URL

这是nginx配置文件

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       9090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /srv/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
            error_page 405 =200 http://$host$request_uri;
        }

       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:8080/;
        }

        #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   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;
        #}
    }
 

 

 

...全文
成就一亿技术人!
拼手气红包 10.00元
1557 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

看日志,请求能不能打到接口里

老王就是我 2023-08-29
  • 打赏
  • 举报
回复

图片转base64不就得了

  • 打赏
  • 举报
回复

根据你提供的配置文件,可能是由于您的Nginx配置文件中缺少对验证码图片的正确代理设置。

在您的配置文件中,我看到了以下代理设置:

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:8080/;
}

这个配置块是用来将请求代理到后端API服务器的。然而,验证码图片并不是在这个路径下。您需要为验证码图片添加一个单独的代理配置。假设验证码图片的路径为/captcha.jpg,可以尝试在server块中添加以下配置:

location /captcha.jpg {
    proxy_pass http://127.0.0.1:8080/captcha.jpg;
}

把对/captcha.jpg路径的请求代理到后端的http://127.0.0.1:8080/captcha.jpg路径上,以便正确获取验证码图片。

确保在添加或修改配置后重新加载Nginx服务以使更改生效。使用以下命令重新加载Nginx:

sudo service nginx reload

尝试以上步骤后,刷新页面并查看验证码图片是否能够正确显示。

【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于SpringBoot的简易问卷调查系统源码+项目说明.zip # Questionnaire ## Introduction 一个基于SpringBoot的简易问卷调查系统 ### Features * 采用Nginx实现前后端分离(并不规范) * 用户管理 * 发布问卷 * 回答问卷 ### ToDo - 后台管理 - 验证码 - 带答案式问卷 - 统计分析 - 导出excel - 权限验证 ### 后端依赖 + SpringBoot 2.1.10 + Mybatis + hutool工具包 + Lombok插件 + PageHelper分页工具 ### 前端依赖 | 框架 | 介绍 | | ------------------------ | ------------------------------- | | BootStrap | 基础的布局框架 | | BootStrap-datetimepicker | 日期选择工具 | | BootStrap-table | 表格显示工具 | | BootStrapValidator | 表单验证工具 | | Jquery | 基础框架,是BootStrap框架的基础 | | Jsrender | 模板引擎,动态生成页面 | | toastr | 提示工具 | ### 开发工具 + IDEA 2018.1.5 ### 如何使用 1. 部署运行环境 * 安装反向代理服务软件Nginx1.14.2,windows或linux版本均可。可参看博文[Nginx简单安装与配置](https://blog.csdn.net/qq_41550842/article/details/103532550),也可自行百度 * 静态html,js,图片等在上面的resource文件夹内,将这些放入服务器中 * Java版本1.8 * mysql5.5 2. 配置文件 * Nginx配置文件,打开nginx.conf文件,进行如下配置 ```nginx server { listen 80; server_name 127.0.0.1; ####需设置服务器ip#### #charset koi8-r; #access_log logs/host.access.log main; location /nginx/ { root html; index index.html index.htm; } #动静分离 location /views/ { ###下面的根目录需要设置为静态资源的根目录,若将代码克隆下来直接放到linux服务器根目录下,则不需要改### root /resource/questionnaire_static_res;#html页面存储位置的根目录 } #该配置是指nginx收到的url中包含/views/的请求,nginx就会去/resource/questionnaire_static_res/views中查找 location /static/ { root /resource/questionnaire_static_res; #同上 } #反向代理,如果nginx匹配完上述两个规则后,未匹配到相应资源,

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧