3 回答

nginx不支持thinkphp的原因
1
ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以nginx默认情况下是不支持thinkphp的。不过我们可以通过修改nginx的配置文件来让其支持thinkphp。
让nginx支持pathinfo,支持thinkphp
1
我们打开nginx的配置文件,如果是想某个站点支持,请打开对应站点的配置文件
如何让nginx支持ThinkPHP框架
2
我们注释掉配置文件中那些被我圈出来的语句(location ~ \.php$ {……}这一段里面的),我们将对这部分进行重写!
如何让nginx支持ThinkPHP框架
3
将重写后的代码添加进去。
如何让nginx支持ThinkPHP框架
4
添加的代码如下:
.........................................
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
...................................

swoole 框架的性能在使用nginx和php-fpm的时候并没有大的提升,如果使用app_server,据作者说性能较php-fpm有2倍的提升。
app_server.php使用官方例子:
1 2 3 4 5 6 7 8 9 10 | <?php define('DEBUG', 'on'); define("WEBPATH", realpath(__DIR__.'/../')); require dirname(__DIR__) . '/libs/lib_config.php'; $server = Swoole\Network\Protocol\WebServer::create(__DIR__.'/swoole.ini'); $server->setAppPath(WEBPATH.'/apps/'); //设置应用所在的目录 $server->setDocumentRoot(WEBPATH); $server->setLogger(new \Swoole\Log\EchoLog(__DIR__."/webserver.log")); //Logger //$server->daemonize(); //作为守护进程 $server->run(array('worker_num' => 1, 'max_request' => 5000, 'log_file' => '/tmp/swoole.log')); |
重点来了,nginx配置:
1 2 3 4 5 6 7 8 9 10 11 12 | location / { if (!-e $request_filename){ proxy_pass http://127.0.0.1:8888; } } location ~ .*\.(php|php5)?$ { proxy_pass http://127.0.0.1:8888; # fastcgi_pass 127.0.0.1:8888; # fastcgi_pass unix:/dev/shm/php-cgi.sock; # fastcgi_index index.php; # include fastcgi.conf; } |
其实有了第一条配置就可以正常访问了(除了首页),增加第二条主要是为了访问首页。

server {
root /alidata/www/vweb/;
server_name 域名;
location / {
#添加了这个也不行
#try_files $uri $uri/ /index.php?$query_string;
#下面这几行是swoole官网设定
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:9501;
}
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
}
}
添加回答
举报