サーバーブロックの設定を間違えた可能性があるため、現在、すべての無効なページは 500 (Internal Server Error) です。
少し前に自分のウェブサイトを閉鎖することに決め、シンプルな 1 ページのサンキュー ホームページを作成しました。ただし、古いリンクや外部サイトは、サイトの他の部分にアクセスしようとしていますが、それらはもう存在しません。
ホームページ以外 (無効な URL) をすべて強制的にホームページにリダイレクトするにはどうすればよいですか?
次のブロックで試しましたが、うまくいきませんでした。
location / {
try_files $uri $uri/ $document_uri/index.html;
}
私の現在の構成は次のとおりです(現在、PHPファイルも提供していません。つまり、ホームページは単純なhtmlです):
server {
server_name www.example.com example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public_html;
index index.php index.html;
location / {
try_files $uri $uri/ $document_uri/index.html;
}
# Disable favicon.ico logging
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Allow robots and disable logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Enable permalink structures
if (!-e $request_filename) {
rewrite . /index.php last;
}
# Handle php requests
location ~ \.php$ {
try_files $uri = 404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_send_timeout 900;
fastcgi_read_timeout 900;
fastcgi_connect_timeout 900;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Disable static content logging and set cache time to max
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires max;
}
# Deny access to htaccess and htpasswd files
location ~ /\.ht {
deny all;
}
# Deny access to hidden files (beginning with a period)
location ~ /\. {
access_log off; log_not_found off; deny all;
}
}