测试服务器上 Nginx 配置是:
rewrite ^/bootstrap/(.*) /bootstrap/$1 break;
rewrite ^(.*)$ /index.php?/$1 last;
访问 www.example.com/bootstrap/demo.css 是可以的,并且 demo 文件位于 /misc.vip/bootstrap/demo.css
但是本地 nginx 必须这样配置才能达到效果:
rewrite ^/bootstrap/(.*) /misc.vip/bootstrap/$1 break;
这是为什么??测试服务器并么有看到对 misc.vip 目录做了什么??
另外, rewrite 的方式是否现在已经不建议了,使用 try_files 应该怎么写?
不吝赐教!!
配置弄好了,这样就OK
server {
listen 80;
server_name admin.vip.xunlei.com;
root /usr/share/nginx/html/xl/admin.vip_center;
index index.php index.html index.htm;
location / {
#try_files $uri $uri/ /index.php?$args;
rewrite ^(.*)$ /index.php?/$1 last;
}
location /static/ {
root /usr/share/nginx/html/xl/admin.vip_center/misc.vip;
index index.html
try_files $uri /static/login.html;
}
location ~* \.(js|jpg|png|css|gif)$ {
root /usr/share/nginx/html/xl/admin.vip_center/misc.vip;
rewrite ^/css/(.*) /css/$1 break;
rewrite ^/js/(.*) /js/$1 break;
rewrite ^/images/(.*) /images/$1 break;
rewrite ^/bootstrap/(.*) /bootstrap/$1 break;
}
……
测试服务器的nginx和本地虚拟机的nginx版本不同,测试服务器版本很老,所以直接把测试服务器nginx规则弄过来是不行的,要这样改一下。还是有的地方不明白,需要深入学习nginx的配置。