网络上很多关于PHP的MVC环境nginx配置,但是运行后问题很多,或根本就不行,估计这些内容都是到处复制或采集的,也不验证。下面分享一个真正能用的MVC配置。
一、环境:
PHP+NGINX+LINUX或WINDOW
二、配置:
请把配置放在nginx的conf目录下,并加载到http{}配置中。
配置是WINDOW或LINUX通用的,只需要把ROOT改一下即可:
#root /var/web/website_dirname; #这是LINUX适用
root M:/web/website_dirname; #这是WINDOW适用
下面是server配置:
server {
listen 80;
server_name www.youweb.com;
#charset koi8-r;
#access_log logs/host.access.log main;
#root /var/web/website_dirname; #这是LINUX适用
root M:/web/website_dirname; #这是WINDOW适用
index index.html index.htm index.php;
location ~ \.(css|js|jpg|jpeg|png|bmp|gif|svg|ttf|woff|woff2|eot|otf|ico|css\.map|min\.map)(.*)$ {
break;
}
location / {
#index index.htm index.html index.php;
#访问路径的文件不存在则重写URL转交给PHP框架处理
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php/?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#加载Nginx默认"服务器环境变量"配置
include fastcgi.conf;
#include fastcgi_params;
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
本文暂时没有评论,来添加一个吧(●'◡'●)