ThinkPHP TP3.2 LNMP Nginx重写配置
服务器运行环境:Centos6.5 64位 LNMP套件[军哥的lnmp.org 1.4版,] PHP5.6
帮一个朋友部署一套tp3.2开发的网站,在安装完lnmp后,并未想启用rewrite重写,去掉index.php。但是发现不做这个好像网站浏览有问题,于是开始了探索过程,百度上的文章同质化太严重,我经过多次探索,解决了其中出现的多个小坑,现在将完整的配置及解决方法贴出来。
问题描述:nginx+php5.6时常出现No input file specified. 偶尔刷新会正常。
解决方式:
1、php.ini
cgi.fix_pathinfo = 1 [修改后——如果没有,自行添加]
cgi.force_redirect = 0 [也许需要修改这个,看注释是针对IIS的]
2、TP配置修改
‘URL_MODEL’ => 3, 文件:\ThinkPHP\Conf\convention.php
完整配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
nginx vhost配置: server { listen 80; #listen [::]:80; server_name 域名; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/TP目录; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } #TP3.2 rewrite location / { try_files $uri @rewrite; } location @rewrite { set $static 0; if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) { set $static 1; } if ($static = 0) { rewrite ^/(.*)$ /index.php?s=/$1; } } location ~ /Uploads/.*\.php$ { deny all; } location ~ \.php/ { if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { } fastcgi_pass unix:/tmp/php-cgi.sock; include fastcgi_params; fastcgi_param SCRIPT_NAME $1; fastcgi_param PATH_INFO $2; fastcgi_param SCRIPT_FILENAME $document_root$1; } location ~ \.php$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_param SCRIPT_FILENAME /home/wwwroot/xxx/$fastcgi_script_name; #/home/wwwroot/xxx/替换成实际目录 include fastcgi_params; } location ~ /\.ht { deny all; } #rewrite结束 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /home/wwwlogs/日志文件名称.log; } |
噢!评论已关闭。