検索
ホームページPHPフレームワークThinkPHPThinkPHP の nginx 構成の落とし穴

THINKPHP の NGINX 構成の落とし穴

今日、tp ベースの高速開発フレームワークを使用しているときにいくつかの問題に遭遇しました:

nginx エラーのスクリーンショット

ThinkPHP の nginx 構成の落とし穴

説明の便宜のため手動で行を折り返します##

// 处理时重写或内部重定向循环
2019/11/11 11:16:06 [error] 15164#15432: *1 rewrite or internal redirection cycle while processing 
    "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index/user/index.html", 
    client: 127.0.0.1, 
    server: xxxxx, 
    request: "GET /index/user/index.html HTTP/1.1", 
    host: "xxxxx", 
    referrer: "xxxxx"


#エラー設定

##larvael 設定を参照

server {
    .
    .
    .
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    .
    .
    .
    location ~ \.php$ {
        fastcgi_pass127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
    .
    .
    .
}

すべてのパスが同じであることが判明し、すべてホームページ効果があることが判明しました

最初の判断は、nginx 書き換えルールに問題があるということでした

# 路径 / 开头之后都走这个匹配
# 如 /index /index/user 
location / {
    # $uri 本地有就返回,或者$uri/ 本地有目录就返回,或者走后面的重写
    # 本地是指在网站根目录下,如 当 $uri=index 就是看根目录下面有 index 文件或者 index/ 目录
    try_files $uri $uri/ /index.php?$query_string;
}

エラーの報告を開始しました

問題を解決する

オンライン クエリの後、tp5 の設定は

    location / {
        try_files $uri $uri/ /index.php$uri;
    }

になるはずです。変更後、問題があることがわかりました。解決されていません。構成を比較すると、

  # location ~ \.php$ 改成  location ~ \.php(.*)$
    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include fastcgi_params;
    }

が解決されていることがわかりました。完全な構成

server {
    listen       80;
    server_name  xxxxxxx ;
    root  www;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    charset utf-8;
    index index.html index.htm index.php;
    location / {
        try_files $uri $uri/ /index.php$uri;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    error_page 404 /index.php;
    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include fastcgi_params;
    }
    location ~ /\.(?!well-known).* {
        deny all;
    }
}

推奨学習:

thinkphp チュートリアル

以上がThinkPHP の nginx 構成の落とし穴の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事はlearnkuで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。