PHP 확장명을 제거하고 싶습니다. 그래서 나는이 코드를 검색하고 시도했다.Nginx 서버가 파일 확장명을 다시 작성한 후 리디렉션하지 않습니다.
잘 작동하지만 존재하지 않는 페이지를 시도했을 때 작동합니다.
"파일을 찾을 수 없습니다." 쓰기 전에 'try_files $ uri ...;' /404.html을 반환합니다.
시도해 보았습니다. try_files $ uri = 404; .php $하지만 모든 페이지는 /404.html로 돌아갑니다.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
include /etc/nginx/default.d/*.conf;
location/{
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
error_page 404 /404.html;
location = /40x.html {
root /var/www/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
어떻게 해결할 수 있습니까 ??