9cubed
ブログ | Tailwind | Vite | Python | Node.js | Linux | PowerShell | その他 | 将棋ウォーズ | 歌の練習
Webサーバー講座

第23回 Laravel用Nginxの設定の訂正

公開日:2021-03-31
更新日:2021-03-31

1. 概要

大変申し訳ございません。。。Nginxの設定が思いっきり間違ってました。
今回は「第21回 Laravelのプロジェクトの作成」のNginxの設定の訂正になります。

2. 動画



3. ドキュメントルートを変更しない場合の設定

http://localhost/app1/public/ のように、「プロジェクト名/public」を付けてアクセスさせる場合は、次のようにします。
server {
    listen       80;
    server_name  localhost;

    # add_header debug_doc_root  $document_root;
    # add_header debug_script    $fastcgi_script_name;

    root /usr/share/nginx/html;

    location / {
        index index.html index.php;
        try_files $uri $uri/ /app1/public/index.php?$query_string;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php-fpm/www.sock;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

4. ドキュメントルートを変更する場合の設定

http://localhost/ だけでアクセスさせる場合には、次のようにします。
変更箇所は、root と try_files の指定だけです。
server {
    listen       80;
    server_name  localhost;

    # add_header debug_doc_root  $document_root;
    # add_header debug_script    $fastcgi_script_name;

    root /usr/share/nginx/html/app1/public;

    location / {
        index index.html index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/run/php-fpm/www.sock;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

YouTube X

新着一覧

  • SCSS のインストールVite
  • Tailwind CSS のプロジェクトの作成Tailwind
  • TypeScriptのプロジェクトの作成Vite
  • Flask のインストールと動作確認Python
  • 簡易Webサーバーの作成Python
  • pipeline で文章の生成Python
  • pipeline で文章の要約Python
  • 音声から文字起こしPython
  • Node.js のインストールNode.js
  • .ps1(PowerShellスクリプト)を実行可能にするPowerShell

アーカイブ

  • 2025/12
  • 2025/11
  • 2025/10
  • 2025/09
  • 2025/08

以前のカテゴリー一覧

  • CakePHP3
  • CentOS7
  • HTML・CSS・JavaScript
  • Haskell
  • JavaScript
  • Kotlin
  • Laravel5
  • PHP
  • Python
  • Ruby
  • RubyOnRails5
  • TypeScript
  • Vue.js
  • Webサーバ講座
  • Webプログラミング講座
  • jQuery
  • linux
  • パソコン講座
  • ブログ
  • プログラミング講座
  • メモ帳作成講座
  • 数学

Copyright © 9cubed. All Rights Reserved.

プライバシーポリシー 利用規約
▲