ubuntu – 启用nginx浏览器捕获特定网址

前端之家收集整理的这篇文章主要介绍了ubuntu – 启用nginx浏览器捕获特定网址前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何为特定URL启用Nginx catch?我有一个 django网络应用程序,我把我的静态文件,如CSS,JavaScript和…放在一个名为静态的文件夹中,我可以通过 http://example.com/static/访问它们,我想配置Nginx n命令只从这个网址捕获这些文件.我已经阅读了 http://www.nginxtips.com/how-to-enable-browser-cache-static-files-on-nginx/但这个选项没有在那里解释.我尝试下面的配置并重新启动我的ngnix服务器,但我有错误.
这是我的站点可用/默认配置文件.有什么问题?
server {
        listen  80;
        listen  443 ssl;
        server_name     www.example.com example.com;
        ssl_certificate /var/www/example/ssl/ssl.crt;
        ssl_certificate_key     /var/www/example/ssl/ssl.key;
        location /static (jpg|jpeg|png|gif|ico|css|js)${
                alias   /var/www/example/static;
                expires 3d;
                add_header Pragma public;
                add_header Cache-Control "public,must-revalidate,proxy-revalidate";

        }
        location /media  {
                alias  /var/www/example/media;
        }
        location / {
                proxy_pass      http://127.0.0.1:8000;
        }
}

这是Nginx日志文件内容……

2014/03/07 13:02:28 [error] 25189#0: *22 open() "/etc/Nginx/html/static/css/wait.css" Failed (2: No such file or directory),client: 2.178.27.157,server: www.example.com,request: "GET /static/css/wait.css HTTP/1.1",host: "example.com",referrer: "http://example.com/"
2014/03/07 13:02:28 [error] 25189#0: *23 open() "/etc/Nginx/html/static/img/infographi.png" Failed (2: No such file or directory),request: "GET /static/img/infographi.png HTTP/1.1",referrer: "http://example.com/"
2014/03/07 13:02:29 [error] 25189#0: *23 open() "/etc/Nginx/html/favicon.ico" Failed (2: No such file or directory),request: "GET /favicon.ico HTTP/1.1",host: "example.com"
2014/03/07 13:08:41 [emerg] 25220#0: invalid location modifier "/static" in /etc/Nginx/sites-enabled/default:8
2014/03/07 13:08:41 [emerg] 25221#0: invalid location modifier "/static" in /etc/Nginx/sites-enabled/default:8
2014/03/07 13:09:50 [emerg] 25255#0: invalid location modifier "/static" in /etc/Nginx/sites-enabled/default:8
2014/03/07 13:09:50 [emerg] 25256#0: invalid location modifier "/static" in /etc/Nginx/sites-enabled/default:8
nginx wiki开始,你似乎在“/ static”和你的正则表达式模式之间有一个空格.位置只需要一个“uri”参数,而不是两个……并且Nginx会将该空格解释为参数分隔符.

此外,您需要告诉您想要使用’〜’或’〜*’修饰符匹配正则表达式的位置块.

你可以试试这个

location ~* "/static.*(jpg|jpeg|png|gif|ico|css|js)$" {

而不是你拥有的,看看它是否符合你的要求.

原文链接:https://www.f2er.com/ubuntu/347869.html

猜你在找的Ubuntu相关文章