【发布时间】:2013-07-03 02:57:44
【问题描述】:
我必须要重定向到一个 nginx 服务器的子域:first.domainOne.com 和 second.domainTwo.net
我的 nginx 站点可用目录中有两个文件(每个文件都有一个符号链接,在站点启用中指向它): first.server 文件内容:
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name first.domainOne.com;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
second.server 文件内容:
server{
server_name second.domainTwo.net;
root /usr/share/nginx/test;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}
当我启用这两个文件时,我只能访问 /usr/share/nginx/www 的内容(如果我去 first.domainOne.com 或 second.domainTwo.net)。
我必须能够显示我的第二台服务器的内容 (/usr/share/nginx/test) 的唯一方法是禁用(删除)sites-enable 中的 first.server 文件。
这是我的 nginx.conf :
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
编辑:两个重定向都直接指向服务器名称(即http://server.name),但调试日志显示它检测到使用的两个不同的 URL):
http://first.domainOne.com -> http://server.name
http://second.domainTwo.net -> http://server.name
server.name 是托管我的 nginx 实例的服务器。
我想念什么?我的配置文件不正确还是我需要在 nginx.conf 中激活一个选项?
【问题讨论】:
-
你是在本地机器上测试吗?
-
不,在远程服务器上
-
尝试明确包含
sites-enabled文件,即include /etc/nginx/sites-enabled/first.server;include /etc/nginx/sites-enabled/second.server;,看看顺序是否重要 -
订单很重要。如果我恢复第一个和第二个,第二个(在 nginx.conf 中首先设置)将始终显示(无论 URL 是什么)。我还强调两者都是子域重定向。我不知道这很重要。
标签: nginx