私のサイトにある次のURLを同等にしたいと思います。
/foo/bar
/foo/bar/
/foo/bar/index.html
さらに、2番目の2つのフォームが最初のフォームにHTTP 301リダイレクトを発行するようにします。私は静的なページを提供しているだけで、3番目の形式に従って配置されています。(言い換えると、ユーザーが要求/foo/bar
した場合、ファイルをで受信する必要があります/usr/share/.../foo/bar/index.html
)。
私にはnginx.conf
現在次のものが含まれています:
rewrite ^(.+)/$ $1 permanent;
index index.html;
try_files $uri $uri/index.html =404;
これはのリクエストに対して/foo/bar/index.html
は機能しますが、リクエストし/foo/bar
たり、/foo/bar/
Safariから「リダイレクトが多すぎた」と言われたりすると、無限のリダイレクトループまたはそのようなものがあると思います。説明した方法でnginxを取得してURLをファイルにマッピングするにはどうすればよいですか?
編集:私の完全な構成
nginx.conf
ドメイン名を「example.com」に置き換えた私の全体です。
user www-data;
worker_processes 1;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss application/atom+xml text/javascript image/svg+xml;
server {
server_name www.example.com;
listen 80;
return 301 $scheme://example.com$request_uri;
}
server {
server_name example.com 123.45.67.89 localhost;
listen 80 default_server;
# Redirect /foobar/ to /foobar
rewrite ^(.+)/$ $1 permanent;
root /usr/share/nginx/www/example.com;
index index.html;
try_files $uri $uri/index.html =404;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
これらのファイルは実際にファイルシステムに存在しますか?
—
マイケルハンプトン
@MichaelHamptonはい。のリクエストは、設定さ
—
bdesham
/foo/bar/index.html
れている/usr/share/nginx/www/foo/bar/index.html
か、設定されているファイルを返す必要があります。Webサイト上のすべてのパスは、ファイルシステムのパスに直接対応しています。
@bdesham私は再現できません。ここでは、config paste.ubuntu.com/7501697で
—
Alexey 10年
@AlexeyTen何か違うものを得ているのは奇妙です。それを見てくれてありがとう。私が役立った構成を投稿しました。
—
bdesham