configuration - 確認 - nginx 設定ファイル 分割
Nginxでindex.htmlをルートファイルとして設定するには? (3)
ドメイン名にindex.htmlを設定する方法(例: https://www.example.com/ : https://www.example.com/ - ユーザーをルートディレクトリのindex.htmlに誘導します。
私は次のようなさまざまなことを試しました:
server {
# some configs
location = / {
index index.html;
fastcgi_index index.html;
}
or
location / {
index index.html;
fastcgi_index index.html;
}
}
何も私を助けなかった。
私はそれらのいずれかをコメントしましたが、場所のキーワードを持ついくつかの他の設定があります。
他の "location"はserver {
config server {
節:
location ~ .*(css|htc|js|bmp|jp?g|gif|ico|cur|png|swf|htm?|html)$ {
access_log off;
root $www_root;
}
location ~ \.php$
{
include /etc/nginx/fastcgi_params;
index index.html;
fastcgi_index index.html;
fastcgi_param SCRIPT_FILENAME $www_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
# Директива определяет что ответы FastCGI-сервера с кодом больше или равные 400
# перенаправлять на обработку nginx'у с помощью директивы error_page
fastcgi_intercept_errors on;
break;
}
location ~ /\.ht {
deny all;
}
それらはすべてコメントされ、コメントが外されたが、何も助けられなかった。
PS版は/etc/nginx/sites-enabled/domainname.comファイルで作成されました。
location / {
は最も一般的な場所です( location {
)。 それはAFAIUと一致します。 私はlocation / { index index.html; }
location / { index index.html; }
サイトのすべてのサブディレクトリに重複したコンテンツがたくさんあるためです。
のアプローチ
try_files $ uri $ uri / index.html index.html;
あなたのサイトには存在してはならないページのためにindex.html
を返すので、上記のコメントで言及されているように、悪いです(任意の$uri
がそれになります)。 また、上の答えで述べたように、 try_files
最後の引数に内部リダイレクトがあります。
あなたのアプローチ
location = / { index index.html;
index
は内部リダイレクトもするので、悪いです。 あなたがそれを望む場合には、特定のlocation
それを扱うことができるはずlocation
。 作成する
location = /index.html {
hereに提案されhere 。 しかし、望んでいないかもしれない作業リンクhttp://example.org/index.html
があります。 私が使用している別の変種は次のとおりです:
root /www/my-root;
# http://example.org
# = means exact location
location = / {
try_files /index.html =404;
}
# disable http://example.org/index as a duplicate content
location = /index { return 404; }
# This is a general location.
# (e.g. http://example.org/contacts <- contacts.html)
location / {
# use fastcgi or whatever you need here
# return 404 if doesn't exist
try_files $uri.html =404;
}
PS nginxをdebugのは非常に簡単です(バイナリであれば)。 server {
追加するだけですserver {
ブロック:
error_log /var/log/nginx/debug.log debug;
すべての内部リダイレクトなどが表示されます
あなたの位置ブロックで行うことができます:
location / {
try_files $uri $uri/index.html;
}
これはngingxに最初に与えられた正確な名前のファイルを探すように指示し、そうしたファイルが見つからなければuri / index.htmlを試します。 したがって、 https://www.example.com/リクエストがあった場合は、最初に正確に一致するファイルが検索され、見つからない場合はindex.htmlを確認します
答えは、ルートディレクトリを場所ディレクティブに配置することです。
root /srv/www/ducklington.org/public_html;