Nginxを使用して、特定のWebサイトを表示することにより、サーバーのIPを指すすべてのドメインを受け入れるようにサーバーを構成しようとしていますが、www.example.com(メインWebサイト)にアクセスすると、その他のコンテンツ。
これが私がこれまでにしたことです:
server {
// Redirect www to non-www
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
// rest of the configuration
}
server {
// Catch all
listen 80 default_server;
// I also tried
// server_name _;
// Without any luck.
// Rest of the configuration
}
この構成の問題は、www.example.com または example.com ではないこのサーバーに対して行われたすべての要求が、キャッチオールではなく、example.com サーバー構成の下で取得されることです。
最初の 2 つの構成では www.example.com/example.com のみを使用し、最後の構成では他のすべてを使用したいと思います。