nginx
判断是否能找到该文件,如果找不到,则进行url重写
if (!-f $request_filename){
rewrite (.*) /index.php;
}
location /jitamin/public/{
if (!-f $request_filename){
rewrite ^/jitamin/public/(.*)$ /jitamin/public/index.php;
}
if (!-e $request_filename){
rewrite ^/jitamin/public/(.*)$ /jitamin/public/index.php;
}
}
nginx作用
前端服务器:负责http请求解析转发,或者处理静态请求。轻量级,并发量高,可以作为反向代理,负载均衡。
应用服务器:负责调用某种语言的解释器,或则某某种语言写的程序,接受http请求,按照开发者意图做出动作,把结果返回给请求。
Nginx不只有处理http请求的功能,还能做反向代理。Nginx通过反向代理功能将动态请求转向后端Php-fpm。
location ~ .php${
include ...../nginx/fastcgi.conf; #加载nginx的fastcgi模块
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000; #nginx fastcgi进程监听的IP地址和端口
}
php-fpm是fastcgi的实现,并提供了进程管理功能。进程包含了master和worker两种进程。
master进程只有一个,负责监听端口,接收webserver请求;然而worker进程有多个,每个进程都嵌入了php解释器,是php代码真正执行的地方。
apache
- httpd.conf配置文件中加载了mod_rewrite.so模块
- AllowOverride None 将None改为 All
- 在应用入口文件同级目录添加.htaccess文件,内容如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>