301을 사용하여 도메인을 포트 8000으로 리디렉션하는 Nginx

301을 사용하여 도메인을 포트 8000으로 리디렉션하는 Nginx

내 nginx 서버가 한 도메인에서는 301 리디렉션을 발생시키고 다른 도메인에서는 발생하지 않는 이유를 알아내기 위해 모든 곳을 조사해 왔습니다. 이 서버에는 아파치 스타일(사이트 사용 가능)로 구성된 두 개의 사이트가 있습니다. domain1.com과 domain2.com을 가정해 보겠습니다. PHP-FPM도 실행 중입니다. 구성은 다음과 같습니다.

Domain1.com

server {
        listen   80; ## listen for ipv4; this line is default and implied
        server_name domain1.com www.domain1.com; 

        root /var/www/domain1.com;
        index index.php index.html index.htm;


        location / { 
                try_files $uri $uri/ /index.php?$args;
        }   

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #   
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }   

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #   
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }   

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one 
        #   
        location ~ /\.ht {
                deny all;
        }   
}

Domain2.com

server {
        listen   80; ## listen for ipv4; this line is default and implied
        server_name domain2.com www.domain2.com; 

        root /home/mike/www;
        index index.php index.html index.htm;


        location / { 
                try_files $uri $uri/ /index.php?$args;
        }   

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #   
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }   

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #   
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }   

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one 
        #   
        location ~ /\.ht {
                deny all;
        }   
}

server_name과 루트를 제외하면 기본적으로 완전히 동일하다는 것을 알 수 있습니다. 그렇지 않으면 동일합니다. 이제 상황은 이렇습니다. domain1.com은 문제 없이 잘 작동합니다. domain2.com의 DNS가 서버로 변경되지 않았을 때, domain2 사이트는 Listen 8000을 사용하여 한 번 테스트되었습니다. IP:8000으로 테스트해보니 잘 되서 도메인으로 변경하고, 포트도 80으로 변경하고, DNS도 변경해 줬습니다. 이후 서버의 전원을 완전히 껐다 켜고 nginx와 php5-fpm이 100번 정도 다시 시작되었습니다.

브라우저에서 domain2.com을 방문하면 자동으로 domain2.com:8000으로 리디렉션됩니다. web-sniffer.net을 사용하고 HTTP 헤더를 보면 301 리디렉션이 반환됩니다. 저는 리디렉션을 설정한 적이 없으며 이 서버 어디에도 301 설정이 없습니다. 정말 문제가 되는 점은 www.domain2.com을 방문하여 server_name 아래의 nginx 구성 파일에서 도메인을 제거했을 때 기본 nginx 페이지가 표시된다는 것입니다. 이는 제대로 작동한다는 의미입니다. 구성의 server_name 지시문에 www.domain2.com을 추가하면 301 리디렉션이 다시 시작됩니다.

nginx.conf의 http 섹션 아래에 port_in_redirect off도 추가했는데 아무 것도 하지 않는 것 같습니다.

여기서 무슨 일이 일어나고 있는지 아는 사람 있나요?

편집: 컬-vhttp://domain2.com

* About to connect() to domain2.com port 80 (#0)
*   Trying 162.243.XXX.XXX... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: domain2.com
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.1.19
< Date: Mon, 13 Jan 2014 17:37:07 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.3.10-1ubuntu3.9
< X-Pingback: http://162.243.XXX.XXX:8000/xmlrpc.php
< Location: http://domain2.com:8000/
< 
* Connection #0 to host domain2.com left intact
* Closing connection #0

답변1

서버의 실제 출력을 보지 않고는 추측하기가 조금 어렵습니다. curl -v http://example2.com/실제로 반환된 내용을 보려면 를 사용하는 것이 좋지만 브라우저가 리디렉션을 캐시한 것 같습니다. 나는 그것을 전에 본 적이 있습니다.

다른 브라우저를 사용해도 동일한 리디렉션이 표시됩니까?

업데이트: 진단 결과에 따르면 이는 nginx.

관련 정보