Nginx try_files不会搜索文件

时间:2017-09-20 14:59:44

标签: nginx

重新安装ubuntu后,nginx配置不想工作。 try_files具有正确的root路径,找不到文件。 这是我的配置

server {
       listen 80;
       listen 443 ssl;
       server_name maiden.local evermaiden.local;

       root /home/aeonax/lid/evermaiden/resources/public;
       access_log /home/aeonax/lid/evermaiden/resources/public/logs/nginx.log mrgl;

       location / {
                   try_files $uri $uri/ @clj;
                   proxy_set_header Host $host;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       }

       location @clj {
                   proxy_pass http://0.0.0.0:4444;
                   proxy_set_header Host $host;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       }
}

日志格式:

log_format mrgl '\n uri: $uri'
                '\n document root: $document_root'
                '\n realpath root: $realpath_root'
                '\n doc + uri: $document_root$uri';

日志输出:

uri: /test.jpg
document root: /home/aeonax/lid/evermaiden/resources/public
realpath root: -
doc + uri: /home/aeonax/lid/evermaiden/resources/public/test.jpg

uri: /assets/common.css
document root: /home/aeonax/lid/evermaiden/resources/public
realpath root: -
doc + uri: /home/aeonax/lid/evermaiden/resources/public/assets/common.css

uri: /assets/evermaiden.js
document root: /home/aeonax/lid/evermaiden/resources/public
realpath root: -
doc + uri: /home/aeonax/lid/evermaiden/resources/public/assets/evermaiden.js

这里出了什么问题? Nginx可以访问该文件夹(日志文件工作正常),所有文件都存在并存储在logs / nginx.log附近...第一个请求应该返回图像,但是它继续到服务器-_-另一个请求应该返回资产,但是...
我尝试用purge nginx nginx-common nginx-full重新安装它,我尝试了其他版本(1.12-> 1.13),但它仍然不起作用。

1 个答案:

答案 0 :(得分:0)

感谢@TarunLalwani我记得/ var / logs中的默认日志以及当我访问它时......它是 facepalm -_-

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

在此之后,问题消失了,我找到了解决方案here

 2017/09/20 23:13:44 [crit] 30316#30316: *1 realpath() "/home/aeonax/lid/evermaiden/resources/public" 
 failed (13: Permission denied) while logging request, client: 127.0.0.1, server: maiden.local, 
 request: "GET /test.jpg HTTP/1.1", upstream: "http://0.0.0.0:4444/test.jpg", host: "maiden.local"