0

我必须要重定向到一个 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)的唯一方法是从站点启用中禁用(删除)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 中的选项?

4

1 回答 1

0

Nginx 支持多个服务器块,您的语法看起来很合理。我怀疑问题可能出在上面没有看到的东西上。尝试继续缩小搜索服务器块,看看是否可以通过这种方式找到问题。您也可以尝试从 /etc/nginx/conf.d/*.conf 中删除其他文件以继续简化问题。

遵循Nginx 的一般调试提示也可以解决您的问题。

您也可以尝试从简单的 Nginx 服务器块示例开始,然后构建它们以满足您的需求。

最后,您的散文提到涉及重定向,但我在您粘贴的代码中看不到重定向。您发布的内容中是否缺少配置的一部分?问题可能就在那里。

于 2013-07-02T18:27:51.673 回答