开发者社区> 问答> 正文

nginx expires 无效:配置报错 

server {
        listen       80;
        server_name  abcdefg.cn;

        location / {
            root   html/abcdefg.cn;
            index  index.php index.html index.htm;
		if (!-f $request_filename){
			set $rule_1 1$rule_1;
		}
		if (!-d $request_filename){
			set $rule_1 2$rule_1;
		}
		if ($rule_1 = "21"){
			rewrite /. /index.php last;
		}
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           html/abcdefg.cn;
            fastcgi_pass   unix:/var/run/php-fpm.socket;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/abcdefg.cn$fastcgi_script_name;
            include        fastcgi_params;
        }

	
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

    }
最后一个location
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
开启后网站的css、js、图片等全部无法加载,求解。

展开
收起
kun坤 2020-06-04 10:12:19 1022 0
1 条回答
写回答
取消 提交回答
  • location加上root######谢了~最后一个location加上root,刚才我加的时候少了个“;”号,嘿嘿!######第一个location已经加了root######

    # 设置expires和max-age的时间 location ~* "^.+.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" { expires         30d; log_not_found   off; }

    2020-06-04 13:25:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载