Customize Consent Preferences

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. ... 

Always Active

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.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

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.

No cookies to display.

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.

No cookies to display.

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.

No cookies to display.

Laravelを使ってみよう【#15】Nginxの設定を変える

2023年02月17日

Laravelで早速エラーが出た

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にアクセスしてみると…

ちゃんと表示できました。

ようやくスタートラインに立てた気分です。

ここからはスピード上げていきたいと思います。

お知らせ

株式会社プラン・ドゥでは一番くじなどで馴染みのあるミシン目の入ったくじの販売を行なっております。



他社ではなかなかできない製品を最適な価格でご案内させていただいておりますのでぜひお問い合わせください。その他の取扱商品はこちらからご覧いただけます。
https://plando-inc.co.jp/product
前の記事 次の記事

同じカテゴリの記事

関連記事

スポンサーリンク

DTP

Laravel開発

wordpressカスタマイズ

デジタルマーケティング

ライフハック

動画

当社製品について

Contact各種お問い合わせ

お問い合わせ・ご相談など
まずはお気軽にご相談ください

お仕事のご依頼やご相談、弊社サービス内容に関してなど、お気軽にご相談ください。

トップページ コラム 各種お問い合わせ プライバシーポリシー