【PHP开辟框架】ThinkPHP 的 nginx 设置踩坑
2019-11-14php框架搜奇网114°c
A+ A-
THINKPHP 的 NGINX 设置踩坑
本日在用一个以 tp 为基本的疾速开辟框架时碰到一些题目:
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 设置踩坑的细致内容,更多请关注ki4网别的相干文章!
标签:ThinkPHP