【发布时间】:2013-03-23 01:38:34
【问题描述】:
在我的域下,比如说example.com,我想要一个登录页面(点击example.com 时会出现)、一个WordPress 博客(将在blog.example.com 运行)和我的HTML 简历(它将住在resume.example.com)。使用 nginx,我想拥有三个单独的 .conf 文件,以便我可以将它们彼此分开。 DNS 设置为“resume”和“blog”是example.com 的 A 记录。
我在 Linode 上运行它,因此我可以完全控制 DNS 和 Web 服务器。但是,当我尝试将 blog.example.com 的 nginx .conf 条目拆分为单独的文件时,当我在 Web 浏览器中点击它时,我会得到从 blog.example.com 到 www.example.com 的重定向。
我知道安装 WordPress 不是问题,因为当所有三个服务器条目都在一个 nginx 文件中时,一切正常。我还尝试为博客创建一个单独的文件夹结构(blogs-available 和 blogs-enabled),然后将这些文件夹包含在 nginx.conf before sites-enabled 包含中,但这不起作用任何一个。这给我留下了两个问题:
是否有人对如何使其工作有任何建议?也许我的 DNS 设置不正确。
nginx 关心加载顺序还是不明确?如果是后者,那么我会将所有内容保存在一个服务器块中,要么全部启动,要么全部关闭。
更新:
nginx.conf for 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 站点,但这应该是微不足道的。另外,上述工作顺序不限,所以我不认为这是重定向问题。
** 第二次更新**
凭直觉,我在example.com conf 文件中注释掉了以下内容:
server {
listen <ip-address>:80;
server_name example.com;
rewrite ^(.*)$ $scheme://www.example.com$request_uri? permanent;
break;
}
它按我的预期工作。我上面的非 www -> www 重定向规则有问题吗?
【问题讨论】:
-
这是 301 重定向还是只是内容来自 www.example.com?在此处发布您的配置文件,我们可以有更具体的建议。顺便说一句,这应该是 nginx 中的一个简单设置,可以在一个服务器中支持多个域。
-
nginx 配置没问题。更新了我的答案。
标签: wordpress dns nginx webserver