猿问
下载APP

请问使用swoole框架还用 nginx吗

请问使用swoole框架还用 nginx吗

繁花不似锦
浏览 82回答 3
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使用官方例子:12345678910<?phpdefine('DEBUG',&nbsp;'on');define("WEBPATH",&nbsp;realpath(__DIR__.'/../'));require&nbsp;dirname(__DIR__)&nbsp;.&nbsp;'/libs/lib_config.php';$server&nbsp;=&nbsp;Swoole\Network\Protocol\WebServer::create(__DIR__.'/swoole.ini');$server->setAppPath(WEBPATH.'/apps/');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置应用所在的目录$server->setDocumentRoot(WEBPATH);$server->setLogger(new&nbsp;\Swoole\Log\EchoLog(__DIR__."/webserver.log"));&nbsp;//Logger//$server->daemonize();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//作为守护进程$server->run(array('worker_num'&nbsp;=>&nbsp;1,&nbsp;'max_request'&nbsp;=>&nbsp;5000,&nbsp;'log_file'&nbsp;=>&nbsp;'/tmp/swoole.log'));重点来了,nginx配置:123456789101112location&nbsp;/&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!-e&nbsp;$request_filename){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass&nbsp;http://127.0.0.1:8888;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}location&nbsp;~&nbsp;.*\.(php|php5)?$&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass&nbsp;http://127.0.0.1:8888;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass&nbsp;127.0.0.1:8888;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass&nbsp;unix:/dev/shm/php-cgi.sock;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_index&nbsp;index.php;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;fastcgi.conf;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}其实有了第一条配置就可以正常访问了(除了首页),增加第二条主要是为了访问首页。&nbsp;&nbsp;

慕神8447489

server {root /alidata/www/vweb/;server_name 域名;location / {#添加了这个也不行#try_files $uri $uri/ /index.php?$query_string;#下面这几行是swoole官网设定if (!-e $request_filename) {proxy_pass&nbsp;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;}}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答