2017-10-30 4 views
0

nginx 파일에 Cloudflares ips를 추가해야합니다. 나는이 덩어리 블록이 정확히 수행되는지 확신하지 못한다. 나는 위치 지시자를 상상할 것이다.CloudFlare의 ips를 최소한의 nginx 설정에 추가하는 방법

내가 제대로 내 최소한의 nginx 프록시 설정 파일이 IPS

allow 103.21.244.0/22; 
allow 103.22.200.0/22; 
allow 103.31.4.0/22; 
allow 104.16.0.0/12; 
allow 108.162.192.0/18; 
allow 141.101.64.0/18; 
allow 162.158.0.0/15; 
allow 172.64.0.0/13; 
allow 173.245.48.0/20; 
allow 188.114.96.0/20; 
allow 190.93.240.0/20; 
allow 197.234.240.0/22; 
allow 198.41.128.0/17; 
allow 199.27.128.0/21; 
set_real_ip_from 103.21.244.0/22; 
set_real_ip_from 103.22.200.0/22; 
set_real_ip_from 103.31.4.0/22; 
set_real_ip_from 104.16.0.0/12; 
set_real_ip_from 108.162.192.0/18; 
set_real_ip_from 141.101.64.0/18; 
set_real_ip_from 162.158.0.0/15; 
set_real_ip_from 172.64.0.0/13; 
set_real_ip_from 173.245.48.0/20; 
set_real_ip_from 188.114.96.0/20; 
set_real_ip_from 190.93.240.0/20; 
set_real_ip_from 197.234.240.0/22; 
set_real_ip_from 198.41.128.0/17; 
set_real_ip_from 199.27.128.0/21; 
real_ip_header CF-Connecting-IP; 

를 추가하는 방법을 알고 있어야합니다 Cloudflare에서 SSL을 사용하는 경우

server { 
    listen     80; 
    listen     [::]:80; 
    server_name    my.domain.tld; 
    access_log    /var/log/nginx/access.log combined; 
    error_log    /var/log/nginx/error.log warn; 
    return 301    https://$host$request_uri; 
} 
server { 
    listen     443 ssl http2; 
    listen     [::]:443 ssl http2; 
    server_name    my.domain.tld; 
    access_log    /var/log/nginx/access.log combined; 
    error_log    /var/log/nginx/error.log warn; 
    ssl      on; 
    ssl_certificate   /certs/cloudflare/my.domain.tld.crt.pem; 
    ssl_certificate_key  /certs/cloudflare/my.domain.tld.key.pem; 
    client_max_body_size 100M; 

    location/{ 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_pass   http://127.0.0.1:8087; 
    } 
} 

내가이 필요 믿습니다. 여기

답변

0

당신이 당신의 nginx의 설정에 CloudFlare의 IP를 추가하는 방법입니다

server { 
    listen     80; 
    listen     [::]:80; 
    server_name    my.domain.tld; 
    access_log    /var/log/nginx/access.log combined; 
    error_log    /var/log/nginx/error.log warn; 
    return 301    https://$host$request_uri; 
} 
server { 
    listen     443 ssl http2; 
    listen     [::]:443 ssl http2; 
    server_name    my.domain.tld; 
    access_log    /var/log/nginx/access.log combined; 
    error_log    /var/log/nginx/error.log warn; 
    ssl      on; 
    ssl_certificate   /certs/cloudflare/my.domain.tld.crt.pem; 
    ssl_certificate_key  /certs/cloudflare/my.domain.tld.key.pem; 
    client_max_body_size 100M; 

    allow 103.21.244.0/22; 
    allow 103.22.200.0/22; 
    allow 103.31.4.0/22; 
    allow 104.16.0.0/12; 
    allow 108.162.192.0/18; 
    allow 141.101.64.0/18; 
    allow 162.158.0.0/15; 
    allow 172.64.0.0/13; 
    allow 173.245.48.0/20; 
    allow 188.114.96.0/20; 
    allow 190.93.240.0/20; 
    allow 197.234.240.0/22; 
    allow 198.41.128.0/17; 
    allow 199.27.128.0/21; 
    set_real_ip_from 103.21.244.0/22; 
    set_real_ip_from 103.22.200.0/22; 
    set_real_ip_from 103.31.4.0/22; 
    set_real_ip_from 104.16.0.0/12; 
    set_real_ip_from 108.162.192.0/18; 
    set_real_ip_from 141.101.64.0/18; 
    set_real_ip_from 162.158.0.0/15; 
    set_real_ip_from 172.64.0.0/13; 
    set_real_ip_from 173.245.48.0/20; 
    set_real_ip_from 188.114.96.0/20; 
    set_real_ip_from 190.93.240.0/20; 
    set_real_ip_from 197.234.240.0/22; 
    set_real_ip_from 198.41.128.0/17; 
    set_real_ip_from 199.27.128.0/21; 
    real_ip_header CF-Connecting-IP; 

    location/{ 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_pass   http://127.0.0.1:8087; 
    } 
} 
관련 문제