基于DNS的NGINX负载平衡
我在我的cpanle中使用nginx,我在其中有多个子域,我正在尝试在这些域之间进行负载平衡基于DNS的NGINX负载平衡,nginx,nginx-reverse-proxy,Nginx,Nginx Reverse Proxy,我在我的cpanle中使用nginx,我在其中有多个子域,我正在尝试在这些域之间进行负载平衡 这是我的nginx配置 server { server_name alparslan.qsinav.com www.alparslan.qsinav.com; listen 80; set $CPANEL_APACHE_PROXY_IP 213.159.7.72; listen 443 ssl; ssl_certificate /var/cpanel/ssl/
这是我的nginx配置
server {
server_name alparslan.qsinav.com www.alparslan.qsinav.com;
listen 80;
set $CPANEL_APACHE_PROXY_IP 213.159.7.72;
listen 443 ssl;
ssl_certificate /var/cpanel/ssl/apache_tls/alparslan.qsinav.com/combined;
ssl_certificate_key /var/cpanel/ssl/apache_tls/alparslan.qsinav.com/combined;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ALL:!ADH:+HIGH:+MEDIUM:-LOW:-EXP;
root /home/qsinav/public_html/alparslan/public;
index index.php index.html;
access_log /var/log/nginx/access.log upstreamlog;
location = /FPM_50x.html {
try_files $uri $uri/ /index.php$is_args$args;
# root /etc/nginx/ea-nginx/html;
}
include conf.d/server-includes/*.conf;
include conf.d/users/qsinav/*.conf;
include conf.d/users/qsinav/alparslan.qsinav.com/*.conf;
location / {
try_files $uri $uri/ /index.php$is_args$args;
proxy_pass http://backend2;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# proxy_set_header HTTPS "on";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
}
set $fpm_socket "unix:/opt/cpanel/ea-php74/root/usr/var/run/php-fpm/58ea52f18cb33ca4e5a37e3fd6c39780e15caa8c.sock";
location ~ \.php7?$ {
fastcgi_read_timeout 600s;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
include conf.d/includes-optional/cpanel-fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass $fpm_socket;
# fastcgi_pass unix:/opt/cpanel/ea-php74/root/usr/var/run/php-fpm/58ea52f18cb33ca4e5a37e3fd6c39780e15caa8c.sock;
error_page 502 503 /FPM_50x.html;
}
include conf.d/includes-optional/cpanel-cgi-location.conf;
include conf.d/includes-optional/cpanel-server-parsed-location.conf;
}
这是我的上游配置
upstream backend2 {
zone backend 64k; # Use NGINX Plus' shared memory
least_conn;
server demo.qsinav.com weight=1;
server netcom.qsinav.com weight=4;
}
问题是它重定向到cpanel的IP地址,而不是域,因此服务器无法加载数据这是我的访问日志
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.471msec 1605268126.477 request_time 0.472
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.472msec 1605268126.477 request_time 0.473
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.473msec 1605268126.477 request_time 0.473
alparslan.qsinav.com to :212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.474msec 1605268126.477 request_time 0.474
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.475msec 1605268126.477 request_time 0.474
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.479msec 1605268126.478 request_time 0.479
alparslan.qsinav.com to : 212.156.7.72:443[GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.480msec 1605268126.478 request_time 0.479
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.480msec 1605268126.478 request_time 0.480
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.481msec 1605268126.479 request_time 0.482
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.482msec 1605268126.479 request_time 0.482
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.482msec 1605268126.479 request_time 0.483
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.483msec 1605268126.479 request_time 0.484
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.485msec 1605268126.479 request_time 0.484
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.485msec 1605268126.479 request_time 0.485
alparslan.qsinav.com to : 213.159.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.486msec 1605268126.479 request_time 0.486
alparslan.qsinav.com to : 213.159.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.487msec 1605268126.479 request_time 0.486
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.487msec 1605268126.480 request_time 0.488
alparslan.qsinav.com to : 212.156.7.72:443 [GET /storage/files/mu%C5%9F%20alparslan/loginscreen.jpg HTTP/1.1]upstream_response_time 0.488msec 1605268126.480 request_time 0.489
正如您从日志中看到的,它正在尝试使用ip地址加载,无法访问文件
那么我该如何解决这个问题呢?如何实现基于dns的负载平衡