2017-10-06 4 views
0

NGINX와 어려움을 겪고 있고 내 v-hosts를 설정하는 중입니다. HTTP 요청을 HTTPS로 리디렉션 한 다음 내 애플리케이션 (443)으로 리디렉션하는 가상 호스트를 설정하려고합니다.NGINX SSL 리디렉션이 너무 많습니다.

내 OS는 Ubuntu 16.04이고 NGINX 1.10.3을 사용하고 있습니다.

user www-data; 
worker_processes auto; 
pid /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; 
    server_tokens off; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_prefer_server_ciphers on; 
    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/*; 
} 

내 ServerBlocks의 /의 가상 호스트

가 같이 :

server { 
    listen    443 ssl; 
    server_name   xxx.com; 
    # Prevent MITM 
    add_header   Strict-Transport-Security "max-age=31536000"; 
    ssl_certificate  "/etc/nginx/ssl/xxx.com.pem"; 
    ssl_certificate_key "/etc/nginx/ssl/xxx.com.key"; 
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers   HIGH:!aNULL:!MD5; 
    location/{ 
     proxy_pass  http://localhost:2237; 
    } 
} 
server { 
    listen    80; 
    server_name   xxx.com; 
    return 301   https://$server_name$request_uri; 
} 

이제 문제는 내가 어느 경우에 있다는 것입니다

nginx.conf은 (는 대부분 기본)처럼 보이는 HTTP 또는 HTTPS를 사용하여 HTTPS로 리디렉션하려고하므로 무한 루프의 리디렉션에 빠지게됩니다.

나는 내 실수가 어디인지 전혀 알지 못합니다.

모든 VHost는 단일 파일에 있습니다. 포트 2237의 응용 프로그램은 nodeJS Express 서버입니다. curl -I의 출력이

입니다

: 나는 또한 Cloudflare을 사용하고

편집 (나는 그들로부터 내 SSL 인증서 있어요)

$ curl -I https://example.com 
HTTP/1.1 301 Moved Permanently 
Date: Fri, 06 Oct 2017 19:42:19 GMT 
Content-Type: text/html 
Connection: keep-alive 
Set-Cookie: __cfduid=d827df762e20a4e321b92b34bd15546621507318939; expires=Sat, 06-Oct-18 19:42:19 GMT; path=/; domain=.example.com; HttpOnly 
Location: https://example.com/ 
Server: cloudflare-nginx 
CF-RAY: 3a9b1a6a4e4564d5-FRA 
+0

'nginx -T'를 실행하고 로드되고있는 추가 설정이 없습니다 –

+0

@TarunLalwani 아니요, 그 설정은 – dunklesToast

+0

입니다.'proxy_red'는 http : // localhost : 2237/https : // $ host /;를'proxy_pass' 블록에 추가해보십시오. 나는 당신의 nodejs 애플 리케이션이 리다이렉션을 일으킬지도 모르는 리다이렉트를하고 있다고 생각한다. –

답변

1

당신은 설정

server { 
listen    80; 
server_name   example.com; 
add_header   Strict-Transport-Security "max-age=31536000"; 
    location/{ 
    proxy_pass  http://localhost:2237; 
    proxy_redirect http://localhost:2237/ https://$host/; 
    } 
} 

아래에 사용할 필요가 당신의 cloudflare에서 SSL을 종료하고 SSL을 종료합니다. 그래서 당신은 그냥 포트 80에서 듣고 있어야합니다. 이전 설정은 포트 80을 다시 HTTPS로 리디렉션했고 Cloudflare에 요청을 보내서 nginx 포트 80에 보내고 따라서 무한 루프를 만듭니다.

관련 문제