1

我的 manifest.appcache 文件位于http://example.com/manifest.appcache但是 NGINX 正在寻找这个文件/usr/share/nginx/html/manifest.appcache

我什至在我的 example.conf 文件中添加了以下内容:

 location /manifest.appcache {
   try_files $uri  /home/sushi/www/example/manifest.appcache;
 }

我的根设置为

root /home/sushi/www/example/;

我究竟做错了什么?

4

1 回答 1

1

server_name如果这正是您正在使用的,那么您的 nginx 配置看起来不错,那么我不知道到底出了什么问题,但让我整理一下您的配置,可能会有所帮助

对于重定向,我更喜欢使用单独的服务器进行重定向,而不是使用 if 条件

server {
    listen 80;
    server_name www.example.com;
    return 301 example.com$request_uri;
}

无需重新声明根和索引。在服务器块级别指定一次就足够了。

server {
    listen 80;
    server_name example.com;
    root /home/sushi/www/example/;
    access_log /home/sushi/www/example/logs/access.log;
    error_log /home/sushi/www/example/logs/error.log;
    index index.html index.htm;
    location / {
       try_files $uri $uri/ =404;
    }
}

由于您manifest.appcache的确切位置,$uri因此您无需明确提及它,问题是 nginx 与服务器块不匹配。

另一个随机的想法是,也许 nginx 不知道服务器存在,因为您在创建服务器后没有重新启动 nginx ..您尝试过吗?

编辑:里面的块nginx.conf应该移到example.conf文件

server {
    listen 80;
    server_name example.com;
    root /home/sushi/www/example/;
    access_log /home/sushi/www/example/logs/access.log;
    error_log /home/sushi/www/example/logs/error.log;
    index index.html index.htm;
    location / {
       try_files $uri $uri/ =404;
    }
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        expires -1;
        access_log logs/static.log;
    }
}
于 2013-09-21T21:29:05.393 回答