请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

windows,ftp服务器使用nginx代理访问图片404,不访问具体图片可以进入nginx代理界面

这个是nginx配置

server { 
	listen 80;
	autoindex on;
	server_name image.imooc.com;
	access_log c:/nginx/access.log combined;
	index index.html index.htm index.jsp index.php;
	#error_page 404 /404.html;
	if ( $query_string ~* ".*[\;'\<\>].*" ){
		return 404;
	}
	location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
		deny all;
	} 

	location / {
		root C:/ftpserver/ftpfile/img;
		add_header Access-Control-Allow-Origin *;
	}
}

这个是host配置

127.0.0.1		image.imooc.com
127.0.0.1		tomcat.imooc.com

直接输入image.imooc.com是可以进入到Welcome to nginx界面,但是往下找图片就进不去了,上传图片可以上传上去,但是访问就是404

正在回答 回答被采纳积分+3

2回答

Jai周杰 2020-08-31 17:00:23

server {

    listen 80;

#配置跨域

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Headers X-Requested-With;

add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

    autoindex on;

    server_name image.sinochrome.mall.com;

    access_log c:/access.log combined;

    index index.html index.htm index.jsp index.php;

    #error_page 404 /404.html;

    if ( $query_string ~* ".*[\;'\<\>].*" ){

        return 404;

    }


    location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {

        deny all;

    }


    location / {

        root D:/ftpfile/img;

        add_header Access-Control-Allow-Origin *;

    }

}

配置跨域 !

0 回复 有任何疑惑可以回复我~
  • server代码块里加上下面的三个header
    add_header Access-Control-Allow-Origin *;
    
    	add_header Access-Control-Allow-Headers X-Requested-With;
    
    	add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    回复 有任何疑惑可以回复我~ 2020-08-31 17:01:30
geelylucky 2020-08-25 14:55:51

同学,检查一下C:/ftpserver/ftpfile/img这个路径下是否存在你上传的图片,如果没有的话,那就是上传到ftp服务器失败了。

0 回复 有任何疑惑可以回复我~
  • 提问者 慕九州9356372 #1
    这个路径有我上传的照片,但是直接用image.imooc.com访问不到,404
    回复 有任何疑惑可以回复我~ 2020-08-25 16:05:07
  • 老师同样的问题啊,404!
    回复 有任何疑惑可以回复我~ 2020-08-31 15:06:57
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信