我对 nginx 还很陌生,尝试进行简单的重写,但服务器只是响应“404 not found”
我的服务器块
server {
listen 80;
listen [::]:80;
server_name pics.example.com;
root /home/pics;
rewrite ^(.*)$ index.php?tag=$1;
location / {
try_files $uri $uri/ $uri.php /index.html $uri =404;
#try_files $uri =404;
fastcgi_split_path_info ^([a-z]+)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
pics.example.com/foobear
应重写为pics.example.com/index.php?tag=foobear
答案1
删除rewrite
并将该行替换try_files
为以下内容:
try_files $uri $uri/ /index.php?tag=$uri&$args;