之前一直使用apache 服务器,现有一项目想转到Nginx 服务器运行。。
发现Apache 的撰写功能和 Nginx的不一样。无法通用.hataccess 文件
查阅网上资料,nginx 配置转写功能 是直接在配置文件中 配置的:
虚拟服务器设置:
server { listen 81; server_name localhost:81; root "D:/phpStudy/WWW/yii2/anran/backend/web"; location / { index index.html index.php;#默认主页 autoindex on;#是否允许访问目录 include D:/phpStudy/WWW/yii2/anran/backend/web/.htaccess; #关键htaccess 导入 } #php 解析器 location ~ .php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
其中
include D:/phpStudy/WWW/yii2/anran/backend/web/.htaccess; #关键htaccess 导入
是由apache 的.htaccess 转化过来的 网址:http://winginx.com/en/htaccess
原.htaccess
Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php
转换后.htaccess (就是nginx导入的配置)
if (!-e $request_filename){ rewrite ^(.*)$ /index.php; }