访问服务器图片被nginx拦截

博客介绍了服务本地图片的访问方式。未使用Nginx时,可直接通过特定地址访问图片;添加Nginx后,需通过访问Nginx地址来访问图片,经其代理后相当于访问原图片地址,如http://192.168.1.16:80/picture/template/test.jpg 代理 http://127.0.0.1:9207/picture/template/test.jpg。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在服务本地存放的图片
在没有用ngnix的时候可以通过:http://127.0.0.1:9207/picture/template/test.jpg 直接访问
加了ngnix之后就不能直接访问服务器
需要通过ngnix进行访问

   server {
   		# 默认端口
        listen       80;
        # nginx 服务地址
        server_name  192.168.1.16;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		# 匹配picture/ 开头的路由地址转发到  http://127.0.0.1:9207
        location ~picture/* {
			proxy_pass http://127.0.0.1:9207;
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
        }
    }

这样访问图片的时候,就需要通过访问nginx地址访问图片
例如:

http://192.168.1.16:80/picture/template/test.jpg
经过nginx的代理就相当于访问了
http://127.0.0.1:9207/picture/template/test.jpg
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值