【问题标题】:Images not found using Laravel with nginx and docker-compose使用 Laravel 和 nginx 和 docker-compose 找不到图像
【发布时间】:2019-08-22 14:02:32
【问题描述】:

这基本上是我的问题here 的扩展。我现在已经添加了存储文件夹的权限,并且不再出现 500 错误。但现在我得到了 404。

  • 我正在尝试的图像 URL 是 URL:http://localhost:8888/images/content/test/myimage.jpg
  • 图片的服务器路径是/var/www/public/images/content/test/myimage.jpg

我的nginx-config 如下:

user  nginx;
worker_processes  2;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 100000;
events {
    worker_connections  2048;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log  main;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 65;
    gzip on;
    server {
      listen  8888;
      root /var/www/public;
      index index.php index.html index.htm;
      client_max_body_size 100m;
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
      location ~ ^/.+\.php(/|$) {
          fastcgi_pass app:9000;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    }
}

我的猜测是上面的配置有问题,但我不知道它可能是什么。我已经尝试了here 建议的解决方案,但它根本没有任何区别。

有人知道该怎么做吗?

【问题讨论】:

    标签: php laravel docker nginx docker-compose


    【解决方案1】:

    可能是这一行中的路径:location ~ ^/.+\.php(/|$)

    试试这样:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    

    【讨论】:

    • 你能访问索引吗(或者http://localhost:8888也给出了404错误?)
    • 它工作正常,我得到了标准的 Laravel 页面。我还可以访问我创建的任何 API URL:例如 http://localhost:8888/api/content/fetch/test 返回正确的 JSON 对象。
    • 我还尝试在 /var/www/public 中添加一个名为 test.html 的常规 html 文件,该文件刚刚在 body 标记中打印了“hello”,我在该页面上也得到了 404。
    • 试试这个位置 ~ \.php$ { #try_files $uri /index.php =404; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;包括 fastcgi_params; }
    • 您可以为 JPEG 添加另一个位置块吗?例如。 location ~ \.(jpg|jpeg)$ { .. } 是否具有相同的 fastcgi 参数?
    猜你喜欢
    • 2019-09-01
    • 2022-01-09
    • 2018-02-06
    • 1970-01-01
    • 2018-12-28
    • 2020-07-23
    • 2021-02-15
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多