nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?
《nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?》要点: 网络上很多配置nginx的rewrite其实是不可用的,如果想运行vephp、yii、thinkphp等MVC框架,在apache下是很容易的,nginx比较麻烦。 下面这个配置是已应用于vephp框架( www.jb51.cc ),并且对thinkphp也是可用的。并且window和linux通用,只是要把根目录替换一下。 它的原理是:如果服务器上存在该脚本文件就直接访问,如果不存在,则使用MVC框架路由解析。 特分享出来。 server { listen 80; server_name www.jb51.cc;
#charset koi8-r; #access_log logs/host.access.log main; #root /var/www/website; # linux下根目录 root M:/www/website; #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转交给框架处理 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; }
} 如果是apache配置rewrite,则参考这里http://www.jb51.cc/jiaocheng/20.html (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ruby-on-rails – 无法将HTTP响应转发回HTTP客户端:用户似
- Nginx错误日志中的消息“X-Accel-Mapping标头丢失”
- Nginx Angular2/Angular路线
- Postgresql用户没有连接到数据库(Nginx Django Gunicorn)
- 性能-其他解决方案,而不是NGINX的.htaccess
- 为什么nginx为目录别名中的请求提供错误的MIME类型?
- Nginx子域:重定向/.众所周知的加密路径
- nginx – SPDY是否会改善非SPDY CDN提供的资产交付?
- REMOTE_ADDR没有使用nginx龙卷风发送给Django
- ruby-on-rails – 无法通过Passenger/Nginx强制Rails进入生
- ruby-on-rails – 用Bundler安装Gems ==大问题
- 如何使用NGINX阻止洪水请求?
- Nginx-将特定文件或文件夹从日志记录排除到acces
- ruby – Gitlab配置问题:: NGINX Unicorn端口冲突
- 调试Nginx缓存未命中:尽管代理有效,但仍会遇到大
- nginx – 如何在auth_request失败后返回403而不是
- node.js – socket.io何时使用轮询而不是websock
- Nginx – 编码(规范化)URI的一部分
- php – nginx/fastcgi 504网关错误,增加fastcgi_
- ruby-on-rails-如何配置Nginx代理到Rails应用程序