We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ...
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.
2023年02月17日
Laravelを勉強し始めたときにweb.php内に追記して画面を表示させました。この操作をGoogle Cloud上で、サーバーソフトウェアはNginx(エンジンエックス)を使って行っていたのですが、
Route::get('/plando', function () {
return 'palndoと入力した結果です';
});
web.phpにこの動作を追記してアクセスしたところ、404 Not Foundエラーが出てしまいました。最初このエラーが出た時、ディレクトリ権限が足りてなくてLaravelのプロジェクト作成の時に必要なファイルができてなかったのか?と思っていましたがそうでもなさそう。
まずはエラーログを確認してみます。
※以前の記事でLaravalプロジェクトをhtmlのディレクトリと同階層に作ったのですが、VSCodeで編集しようとすると権限が足りなくて編集できなかったのでユーザーディレクトリに変更しました。
秘密鍵を生成するときにもしかしたらユーザー権限を管理者にできるのかもしれないですが、そこまでするメリットを感じなかったのでこの方法を取りました。
スポンサーリンクエラーログは/var/log/nginx/error.log
にあるみたいなのでアクセス。
うーん、いまいちわからない。ファイルがないしかエラーが出てませんね….。調べてみるとnginxのルート設定の問題とのこと。一旦その通り変更してみます。
現状の設定は公開ディレクトリ(root)が/var/www/html/public
。これは問題ないみたい。
変えなければいけないところはlocationの部分で、元々try_files $uri $uri/ =404;
になっていました。これが問題で、意味としてはURLにスラッシュがついているものは404で返すというものだったらしいです。
そりゃあエラー出る上にログにも出るわけないわということでその部分を、try_files $uri/ /index.php?query_string;
に変えてやります。意味としてはスラッシュのついたURLはすべてindex.phpにパラメーターを付けたものに変えるという意味です。へー、こんな設定できるんですね。Apatchにもあるのだろうか、超簡単ですね。
しかもなぜかlocationの後のスラッシュであるべきところがなぜかバックスラッシュになっててこれもエラー出る原因になってました。
改めてhttp://xxx.xx/plandoにアクセスしてみると…
ちゃんと表示できました。
ようやくスタートラインに立てた気分です。
ここからはスピード上げていきたいと思います。
お仕事のご依頼やご相談、弊社サービス内容に関してなど、お気軽にご相談ください。