我对 Nginx 还不太熟悉,所以请多包涵 -
我想要重写一个类似于foo.bar.com/newfoo?limit=30
的URL foo.bar.com/newfoo.php?limit=30
。
这样做似乎很简单rewrite ^([a-z]+)(.*)$ $1.php$2 last;
我感到困惑的是应该把它放在哪里——我尝试过一些位置指令,但做错了。
这是我现有的虚拟主机配置,我应该在哪里实现重写?
server {
listen 80;
listen [::]:80;
server_name foo.bar.com;
root /home/foo;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
}
}
谢谢!
答案1
try_files $uri $uri/ $uri.php /index.html;