Home> PHP Framework> ThinkPHP> body text

ThinkPHP's nginx configuration pitfalls

藏色散人
Release: 2019-11-13 17:53:11
forward
3558 people have browsed it

THINKPHP’s NGINX configuration pitfalls

I encountered some problems today when using a tp-based rapid development framework:

nginx error screenshot

ThinkPHPs nginx configuration pitfalls

Manual line wrapping for convenience of explanation

// 处理时重写或内部重定向循环 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"
Copy after login

Error configuration

Refer to larvael configuration

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; } . . . }
Copy after login

Found that all paths are the same, all have the homepage effect

Initial judgment is that there is a problem with nginx rewriting rules

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

Start to report an error


Solve the problem

After online query, the configuration of tp5 should be

location / { try_files $uri $uri/ /index.php$uri; }
Copy after login

After changing it, I found that the problem was not solved; comparing the configuration, I found that

# 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; }
Copy after login

was solved. Complete configuration

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; } }
Copy after login

Recommended learning:thinkphp tutorial

The above is the detailed content of ThinkPHP's nginx configuration pitfalls. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!