我的本地环境是apache,云服务器的环境是nginx.
为是提高网站性能,减少请求和节省宽带,我本地的apache环境下的程序都会将js和图片以及css等缓存到客户端,apache只需要在..htaccess文件中写入以下代码就可以实现:
<FilesMatch “.(gif|jpg|jpeg|png|ico|swf|js|css)$”>
Header set Cache-Control “max-age=2592000″
</FilesMatch>
但我的服务器环境是nginx,按网上的教程,实现这个功能的配置是:
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 30d;
}
但是,我这样配置nginx后,网站出错了,所有js/css都加载不来,图片显示不出来,更不用说缓存到本地了,请问一下要怎么解决这个问题?
我的nginx.conf如下:
user www www;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 10240;
}
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 80;
server_name
www.77time.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /mnt/wwwroot/dianying;
rewrite ^(.*)movie(.*)\.html$ $1movie.php?id=$2 last;
index index.php index.html index.htm;
}
#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 /mnt/wwwroot/dianying;
}
# 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$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /mnt/wwwroot/dianying$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 30d;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
server_name 77time.com;
rewrite ^(.*)
http://www.77time.com$1 permanent;
}
}
请懂的人帮忙看看。
二十五史资源多多,曹雪芹立书的王熙凤的下场一样凄凉封建颠覆体系的结果!我曾用尽全力,所以不会遗憾。塑造区块链溯源二十五史工程项目资源研究:https://mp.weixin.qq.com/s/7x1MwwpLWUgR6t3V59qeAw
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。