たとえば、私のドメインの下にexample.com
、ランディング ページ ( を押すと表示されるexample.com
)、WordPress ブログ ( にあるblog.example.com
)、および HTML 形式の履歴書( にある) を作成したいと考えていますresume.example.com
。nginx を使用して、3 つの個別の .conf ファイルを用意して、それらを個別に起動および停止できるようにします。DNS は、"resume" と "blog" が の A レコードになるように設定されていexample.com
ます。
これを Linode で実行しているので、DNS と Web サーバーを完全に制御できます。ただし、nginx の .conf エントリを別のファイルに分割しようとすると、Web ブラウザでこれを押すと からへblog.example.com
のリダイレクトが発生します。blog.example.com
www.example.com
WordPress のインストールが問題ではないことはわかっています。3 つのサーバー エントリすべてが 1 つの nginx ファイルにある場合、すべてが正常に機能するからです。また、ブログ用に別のフォルダー構造を作成しようとしました ( blogs-available
and blogs-enabled
)、それらのフォルダーをインクルードのnginx.conf
前に含めましsites-enabled
たが、それもうまくいきませんでした。これにより、2 つの質問が残ります。
これを機能させる方法について何か提案はありますか? 私のDNS設定が間違っている可能性があります。
nginx は読み込み順序を気にしますか、それともあいまいですか? 後者の場合は、すべてを 1 つのサーバー ブロックに保持し、すべてを稼働させるか、すべて停止させます。
アップデート:
のnginx.conf example.com
:
# Blog (WordPress site - blog.example.com)
server {
listen <ip-address>;
server_name blog.example.com;
root /www/blog.example.com/public_html/current;
access_log /www/blog.example.com/logs/access.log;
error_log /www/blog.example.com/logs/error.log;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /www/blog.example.com/public_html/current/$fastcgi_script_name;
if ($uri !~ "^/images/") {
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
}
fastcgi_index index.php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
# redirect example.com to www.example.com
server {
listen <ip-address>;
server_name example.com;
rewrite ^(.*)$ $scheme://www.example.com$request_uri? permanent;
break;
}
# static site - www.example.com
server {
listen <ip-address>;
server_name www.example.com;
# static HTML / soon-to-be Sinatra site
root /www/example.com/public_html/current/public;
access_log /www/example.com/logs/access.log;
error_log /www/example.com/logs/error.log;
}
resume.example.com
注:上記のサイトはありませんが、それは些細なことです。また、上記は任意の順序で機能するため、リダイレクトの問題ではないと思います。
** 2 回目の更新 **
example.com
直感で、 conf ファイルで次のようにコメントアウトしました。
server {
listen <ip-address>:80;
server_name example.com;
rewrite ^(.*)$ $scheme://www.example.com$request_uri? permanent;
break;
}
そして、それは私が期待したように機能しました。上記の非 www -> www リダイレクト ルールに何か問題がありますか?