所以我目前有一台运行nginx的服务器和shoutcast。我正在运行Ubuntu 16.04.4 LTS (GNU/Linux 3.13.0-52-generic x86_64)
。
使用cloudflare我将子域名(使用A记录)链接到我的IP。该子域代理mypi:8000以使用该域访问shoutcast verver。
现在,我开始shoutcast服务器上的每个连接客户端的普通IP,所以每个IP都是相同的,我不能拥有独特的监听器。
这是我的Nginx配置:
##
# Default server configuration
##
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl http2;
ssl on;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name rallypodium.be www.rallypodium.be;
if ($http_host = rallypodium.be){
rewrite (.*) https://www.rallypodium.be$1;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
fastcgi_cache phpcache; # The name of the cache key-zone to use
fastcgi_cache_valid 200 30m; # What to cache: 'Code 200' responses, for half an hour
fastcgi_cache_methods GET HEAD; # What to cache: only GET and HEAD requests (not POST)
add_header X-Fastcgi-Cache $upstream_cache_status; # Add header so we can see if the cache hits or misses
try_files $uri $uri/ /index.php?$query_string;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
##############################################################
# SHOUTCAST SERVER CONFIGURATION
##############################################################
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
server_name stream.rallypodium.be;
location / {
proxy_pass http://serverip:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
serverIP与运行nginx的IP相同。那么“localhost”在这里......有什么想法吗?我已经尝试将set_real_ip_from
添加到所有CF Ip中,然后添加real_ip_header CF-Connecting-IP;
,但这似乎不起作用...
答案 0 :(得分:0)
查看有关如何restore original visitor IP
的Cloudflare文章基本上,您需要使用ngx_http_realip_module和此conf:
server {
listen 80;
server_name www.example.com;
# cloudflare
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 131.0.72.0/22;
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 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;
real_ip_header CF-Connecting-IP;
# ...
}
使用https://www.cloudflare.com/ips
了解IP的最新信息还可以尝试:
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;