nginx 中配置多个location并解决js/css/jpg/等的加载问题

环境:centOS nginx php mysql
情况:静态文件无法加载,包括但不限于css,js,各种图片等
解决方案:nginx.conf中配置,代码如下,需要配置的是上面这个location的内容,下面的是配置php的

		location  ~ .*\.(jpg|jpeg|gif|png|ico|css|js|woff|woff2|ttf|pdf|txt)$ //里面一串为静态文件后缀,需要可继续添加。
        {
            root     /www/blog; //这里为根目录
         }
        location ~ \.php$ {
            root           /www/blog;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

我觉得还是很麻烦,因为静态文件有很多格式,每一种都添加到那一串几乎不可能,如果有其他配置方案,欢迎留言!!!

你可能感兴趣的:(nginx,linux)