我正在从Apache迁移到nginx,需要将大量的httaccess文件转换为nginx格式。
我找到了2种工作方式,我应该使用哪种方式?
location = /test.html { rewrite ^(.*)$ /index.php?action=temp&name=test; }
或只是
rewrite ^/test.html$ /index.php?action=temp&name=test;
我将这一切都放在文件(ez_rewrite_list.conf)中,然后包含在virtual.conf中。我应该把文件放在哪里?有关系吗?我做对了吗?任何提示
server {
listen 80;
server_name test.com;
location / {
root /var/www/com/mysite;
index index.php index.html index.htm;
}
include /etc/nginx/ez_conf/ez_rewrite_list.conf;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/com/mysite;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME document_root$fastcgi_script_name;
include fastcgi_params;
}
}
答案 0 :(得分:2)
你忘了在重写时逃避点(.
)并且它们不完全相同。
技术上确切的位置应该比检查每个请求的regexp快一点。此外,您不需要在位置内重写任何内容,因此我会使用
location = /test.html {
rewrite ^ /index.php?action=temp&name=test;
}
但实际上,你永远不会看到任何差异。