请帮我配置nginx索引文件选项。 除主页面之外的任何请求我都想重定向到某个处理程序文件和主页面请求到index.html文件。
这样的事情:
example.com/123/ -> /root/handler.php
example.com/123.php -> /root/handler.php
example.com/ -> /root/index.html
我使用此配置
listen 80;
server_name domain.com;
root /srv/http/domain.com;
index index.html;
charset utf-8;
access_log /var/log/http/x_nginx_access.log main;
error_log /var/log/http/x_nginx_error.log warn;
auth_basic "Restricted access";
auth_basic_user_file /srv/http/$host/.htpasswd;
location = / {
index index.html;
}
location / {
try_files $uri $uri/ /handler.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\.ht {
deny all;
}
location ~ \.php {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Request-Filename $request_filename;
fastcgi_param SCRIPT_FILENAME /srv/http/$host$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
proxy_read_timeout 512;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}