nginx多个域(每个域的www和非www)

时间:2015-06-10 18:11:31

标签: nginx

我试图在nginx服务器上托管两个域,使用www到非www重定向。这是我的网站配置:

网站1:

// Code goes here
"use strict";
angular.module('tcpApp', [])
.controller('MainCtrl', function($scope) {
  $scope.appNames=[{title:'titre1'},
                   {title:'titre2'},
                   {title:'titre3'}];

})
.directive('programName', function ( $compile ) {
        return {
            restrict    : 'AE',
            replace     : true,
            scope       : {
                            name:'@',
                            index:'@'
                        },

            link        : function (scope, element, attr) {
                            scope.callMe = function () {
                                console.log($(element).prop('class'));
                            }

                            var getTemplate = function( index ) {
                              return Number(index) ? '<h2 class="que t{{index}}" ng-click=callMe()>{{name}}</h2>' : '<h2 class="que t{{index}}" ng-click=callMe()>{{name}}arif</h2>';
                             }

                             element.html(getTemplate(scope.index));

                            $compile(element.contents())(scope);
                        }
        }
    })

网站2:

server {
    root /var/www/afspraken/;
    index index.html index.htm;

    server_name site1.nl;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
server {
    server_name www.site1.nl;
    return 301 $scheme://site1.nl$request_uri;
}

四台服务器中有三台正常工作:server { root /var/www/mijn/; index index.html index.htm; server_name site2.nl; } server { server_name www.site2.nl; return 301 $scheme://site2.nl$request_uri; } www.site2.nlsite2.nl。虽然site1.nl服务器给了我site2。我做错了什么?

1 个答案:

答案 0 :(得分:0)

发现问题。需要首先定义返回301的服务器(在实际处理重定向请求的服务器之前)。工作示例:

server {
        server_name www.mijnbedrijfook.nl;
        return 301 $scheme://mijnbedrijfook.nl$request_uri;
}
server {
    root /var/www/mijn/;
    index index.html index.htm;
    server_name mijnbedrijfook.nl;
}