51,397
社区成员




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;
#}
}
看日志,请求能不能打到接口里
图片转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
尝试以上步骤后,刷新页面并查看验证码图片是否能够正确显示。