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元
1722 3 打赏 收藏 转发到动态 举报
写回复
用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

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

51,407

社区成员

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

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