【问题标题】:Nginx try_files doesnt search filesNginx try_files 不搜索文件
【发布时间】:2018-03-01 17:15:09
【问题描述】:

重新安装 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)但它仍然不起作用。

【问题讨论】:

  • 错误日志说明了什么?

标签: nginx


【解决方案1】:

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

 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"

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


make sure that username group can enter all directories along the path:

chmod g+x /username && chmod g+x /username/test && chmod g+x /username/test/static

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    相关资源
    最近更新 更多