設定に50個ほどの場所エントリがあるサーバーエントリがあり、1つの場所を除いて同じ設定でサーバー上に別のドメインを定義する必要があります。
例えば私は
server {
# the port your site will be served on
# the domain name it will serve for
listen 443 ssl;
server_name example.com sudomain.example.com;
ssl_certificate /etc/loc/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/loc/privkey.pem; # managed by Certbot
proxy_set_header X-Forwarded-Proto https;
location /static/ {
root /srv/sites/example;
}
... # many more location defenition
}
私は次のようなことをする必要がある
location /robots.txt {
if ($host ~ ^\w+\.\w+\.\w+$) {
# subdomains
alias /srv/robots_disallow.txt;
} else {
alias /srv/robots.txt;
}
}
可能であれば、すべての構成をスニペットに抽出し、それをメイン ドメイン用とサブドメイン用の 2 つのサーバー エントリに含めることは避けたいと思います。
コピーしたコードは動作しないことはわかっています。悪であれば
それは何かを示唆する
error_page 418 = @disallow_robots;
location /robots.txt {
alias /srv/robots.txt;
if ($host ~ ^\w+\.\w+\.\w+$) {
# subdomains
return 418;
}
}
location @disallow_robots {
alias /srv/robots_disallow.txt;
}
でも、私はthe "alias" directive cannot be used inside the named location
答え1
map
とステートメントを使用すると、よりクリーンなソリューションを実現できますtry_files
。
例えば:
map $host $robots {
~^\w+\.\w+\.\w+$ /robots_disallow.txt;
default /robots.txt;
}
server {
...
location = /robots.txt {
root /srv;
try_files $robots =404;
}
...
}
見るこのドキュメント詳細については。