1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

laravel nginxでroot以外のページがNot Foundになってしまうとき、これをconfに書く。

Posted at

dockerでngixを追加してやってみたときの話。
rootのいつものLaravelの画面は出るが、追加したURLでNot Foundになってしまう。

404 Not Found
nginx/1.19.0

解決策

try_files $uri $uri/ /index.php?$query_string;を書く

nginx/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; # <==
  }

nginxのconfにこれがないと/以外のときNot foundになる。

dockerでnginxでやろうと思ってやるとはまる。
"Docker Laravel"で検索したページでもここを強調して書かれているところはないと思うので書きました。

公式に書いてました。

参考
Installation - Laravel - The PHP Framework For Web Artisans

1
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?