LoginSignup
2
2

More than 3 years have passed since last update.

laravel、docker、nginxのimageを使ってroot以外のページが404 Not Foundになってしまう

Posted at

laravelの環境をdockerでnginxのimageを使ってやる際に、他のページなどでさらっとnginxのconfが書かれていて、自作したとき、ハマってしまいました。

locationにtry_files $uri $uri/ /index.php?$query_string;がないとroot(localhost/)はページが表示できるのですが、自分で設定したlocalhost/usersなどは404 Not Foundになってしまいます。

答えは公式に書いてました。

default.conf
server {
  listen 80;
    index index.php index.html;
    root /var/www/public;

  location / {
    root /var/www/public;
    index  index.html index.php;
    try_files $uri $uri/ /index.php?$query_string; # <=======これを加筆
  }

  location ~ \.php$ {

    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
  }
 }

参考サイト
Installation - Laravel - The PHP Framework For Web Artisans

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2